Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Odzielenie linków od emotek
armind
post
Post #1





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 15.11.2012

Ostrzeżenie: (0%)
-----


Witam mam skrypcik shoutboxsa oraz funkcje emotek i auto linku jak oddzielić link od emotki bo to wygląda straszliwie

podam przykłąd wpisze http:// - to z - :/ robi sie jeszcze emotka

Ten post edytował armind 24.01.2013, 15:13:07
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
armind
post
Post #2





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 15.11.2012

Ostrzeżenie: (0%)
-----


Tak wywołuje:

".auto_link_text(emoty($row['msg']))."

Oto funckje ktore mam:

  1. function auto_link_text($text) {
  2. $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
  3. return preg_replace_callback($pattern, 'auto_link_text_callback', $text);
  4. }
  5.  
  6. function auto_link_text_callback($matches) {
  7. $max_url_length = 50;
  8. $max_depth_if_over_length = 2;
  9. $ellipsis = '&hellip;';
  10.  
  11. $url_full = $matches[0];
  12. $url_short = '';
  13.  
  14. if (strlen($url_full) > $max_url_length) {
  15. $parts = parse_url($url_full);
  16. $url_short = $parts['scheme'] . '://' . preg_replace('/^www\./', '', $parts['host']) . '/';
  17.  
  18. $path_components = explode('/', trim($parts['path'], '/'));
  19. foreach ($path_components as $dir) {
  20. $url_string_components[] = $dir . '/';
  21. }
  22.  
  23. if (!empty($parts['query'])) {
  24. $url_string_components[] = '?' . $parts['query'];
  25. }
  26.  
  27. if (!empty($parts['fragment'])) {
  28. $url_string_components[] = '#' . $parts['fragment'];
  29. }
  30.  
  31. for ($k = 0; $k < count($url_string_components); $k++) {
  32. $curr_component = $url_string_components[$k];
  33. if ($k >= $max_depth_if_over_length || strlen($url_short) + strlen($curr_component) > $max_url_length) {
  34. if ($k == 0 && strlen($url_short) < $max_url_length) {
  35. // Always show a portion of first directory
  36. $url_short .= substr($curr_component, 0, $max_url_length - strlen($url_short));
  37. }
  38. $url_short .= $ellipsis;
  39. break;
  40. }
  41. $url_short .= $curr_component;
  42. }
  43.  
  44. } else {
  45. $url_short = $url_full;
  46. }
  47.  
  48. return "<a rel=\"nofollow\" href=\"$url_full\" target=\"_blank\">$url_short</a>";
  49. }
  50.  
  51. function emoty($content) {
  52. $content = str_replace("<wesoly>", "<img src=\"emoty/usmiech.gif\" style=\"border:0px;\" />",$content);
  53. $content = str_replace(":-)", "<img src=\"emoty/usmiech2.gif\" style=\"border:0px;\" />",$content);
  54. $content = str_replace(":)", "<img src=\"emoty/usmiech2.gif\" style=\"border:0px;\" />",$content);
  55. $content = str_replace(":-))", "<img src=\"emoty/usmiech2.gif\" style=\"border:0px;\" />",$content);
  56. return $content;
  57. }


Musiałem skrócic - dałem mniej linijek emotek (IMG:style_emoticons/default/biggrin.gif)

Ten post edytował armind 24.01.2013, 16:10:47
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 17.10.2025 - 15:28