Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Emotikony
Forum PHP.pl > Forum > Gotowe rozwiązania
Louner
Witam
Chciałbtm się zapytać, czy istnieje jakiś gotowy skrypt który konwertuje odpowiednie znaki na emotikony? Nie mam jeszcze tyle doświadczenia w programowaniu, żeby napisać własny. Szukałem takowego na stronach:

http://php.skryptoteka.pl/
na hasła: emoty, emotikony, konwerter znaków

http://www.webinside.pl/skrypty
na hasła: emoty, emotikony, emotki

http://www.wirtuals.net/

http://www.megaskrypty.com/index.php?cat=3

http://www.hotscripts.pl/index.php

http://php.resourceindex.com/search/index.cgi


Wszystko okazało się płonne. Czy ktoś mógłby mi pomóc ? sad.gif
crash
  1. <?php
  2. $tekst = str_replace( ':-)', '<img src=\"./usmiech.gif\"/>', $tekst );
  3. ?>

Kombinuj smile.gif
Louner
Hmm. Sprawa jest wg mnie torchę bardziej złożona. Z pomocą bardziej doświadczonych osób jakoś złożyłem (złożyli? winksmiley.jpg) takowy skrypt do newsów:

  1. <?php
  2. $dzial = '8';
  3.  
  4. $sql=&#092;"SELECT p.post_id, pt.post_id, pt.post_text, pt.bbcode_uid, t.topic_id, t.to
    p
  5. c_title, t.topic_first_post_id, t.forum_id, t.topic_replies, u.user_id, 
  6.  
  7. u.username, u.user_posts, u.user_rank
  8.  FROM &#092;".TOPICS_TABLE.\" t, \".USERS_TABLE.\" u, \".POSTS_TABLE.\" p, \".POSTS_TEXT_TABLE.\" pt
  9.  WHERE t.forum_id = $dzial
  10.  AND t.topic_poster = u.user_id
  11.  AND t.topic_first_post_id = pt.post_id
  12.  AND t.topic_first_post_id = p.post_id
  13.  ORDER BY pt.post_id DESC&#092;";
  14.  $query=mysql_query($sql);
  15.  while(
  16.  $result=mysql_fetch_assoc($query))
  17.  {
  18.  $text = $result['post_text'];
  19.  $text = bbcode_strip($text, $result['bbcode_uid']);
  20.  $link = append_sid('viewtopic.' . $phpEx . '?t=' . $result['topic_id']);
  21.  if (strlen($text) > 1000){
  22.  $text = substr($text, 0, 1000).'...[space][space] <a href=\"forum/'.$link.'\" class=\"wiecej\">Wiecej</a>';}
  23.  $text = str_replace('
  24.  ', '<br>', $text);
  25.  $author = ' ';
  26.  echo '<div style=\"text-align:justify; background:#FCFCFC; border: solid #CACACA 1px; padding:5px; margi
    n:5px; font-size:10pt\"><b><a 
  27.  
  28. href=\"forum/'.$link.'\" class=\"tytul_newsa\">'.$result['topic_title'].'</a></b><hr width=\"90%\" align\"center\"><span 
  29.  
  30. class=\"news\">'.$text.'</span><div align=\"right\"><br /><span class=\"autor\">'.$author.' :: </span><a href=\"forum/'.$link.'\" 
  31.  
  32. class=\"autor\">Komentarzy: <span class=\"autor_red\">'.$result['topic_replies'].'</span></a></div></div>';
  33.  }
  34.  ?>


Chodzi mi o to, by w zmiennej $text podmieniało emoty.

  1. <?php
  2. $tekst = str_relpace( ':-)', '<img src=\"./usmiech.gif\"/>', $tekst );
  3. ?>


Mam pytania:
1) nie umiem posługiwać się tą funkcją. Gdzie mam umieścić tekst wiadomości?
2) kiedy używam jej w takiej formie wyświetla mi błąd o odwołaniu do nieistniejącej funkcji. Jak mogę temu zaradzić? smile.gif Domyślam się, że po przecinkach deklaruję jej parametry.
crash
Sorki, zrobiłem literówke tongue.gif Ma być: str_replace" title="Zobacz w manualu PHP" target="_manual. Przy okazji pod tym linkiem znajdziesz informacje jak jej używać...
Louner
Ok, dziękuję. winksmiley.jpg Już wątpiłem, że ktoś mi pomoże biggrin.gif Udało się, zrozumiałem i jest świetnie biggrin.gif Dziękuję winksmiley.jpg

edit:
Niestety nie działa tam gdzie powinno tongue.gif Używam takiego skryptu:

  1. <?php
  2. $text = str_replace(&#092;":)\", \"<img src=\"forum/images/smiles/icon_smile.gif\">\", $text);
  3. $text = str_replace(&#092;";)\", \"<img src=\"forum/images/smiles/icon_wink.gif\">\", $text); 
  4. $text = str_replace(&#092;":P\", \"<img src=\"forum/images/smiles/icon_razz.gif\">\", $text); 
  5. $text = str_replace(&#092;"X)\", \"<img src=\"forum/images/smiles/icon_twisted.gif\">\", $text); 
  6. $text = str_replace(&#092;":D\", \"<img src=\"forum/images/smiles/icon_biggrin.gif\">\", $text); 
  7. $text = str_replace(&#092;":(\", \"<img src=\"forum/images/smiles/icon_sad.gif\">\", $text);
  8. $text = str_replace(&#092;"->\", \"<img src=\"forum/images/smiles/icon_arrow.gif\">\", $text);
  9. $text = str_replace(&#092;";(\", \"<img src=\"forum/images/smiles/icon_cry.gif\">\", $text); 
  10.  
  11. $dzial = '8';
  12.  
  13. $sql=&#092;"SELECT p.post_id, pt.post_id, pt.post_text, pt.bbcode_uid, t.topic_id, t.to
    p
  14. c_title, t.topic_first_post_id, t.forum_id, t.topic_replies, u.user_id, 
  15.  
  16. u.username, u.user_posts, u.user_rank
  17.  FROM &#092;".TOPICS_TABLE.\" t, \".USERS_TABLE.\" u, \".POSTS_TABLE.\" p, \".POSTS_TEXT_TABLE.\" pt
  18.  WHERE t.forum_id = $dzial
  19.  AND t.topic_poster = u.user_id
  20.  AND t.topic_first_post_id = pt.post_id
  21.  AND t.topic_first_post_id = p.post_id
  22.  ORDER BY pt.post_id DESC&#092;";
  23.  $query=mysql_query($sql);
  24.  while(
  25.  $result=mysql_fetch_assoc($query))
  26.  {
  27.  $text = $result['post_text'];
  28.  $text = bbcode_strip($text, $result['bbcode_uid']);
  29.  $link = append_sid('viewtopic.' . $phpEx . '?t=' . $result['topic_id']);
  30.  if (strlen($text) > 1000){
  31.  $text = substr($text, 0, 1000).'...[space][space] <a href=\"forum/'.$link.'\" class=\"wiecej\">Wiecej</a>';}
  32.  $text = str_replace('
  33.  ', '<br>', $text);
  34.  $author = ' ';
  35.  echo '<div style=\"text-align:justify; background:#FCFCFC; border: solid #CACACA 1px; padding:5px; margi
    n:5px; font-size:10pt\"><b><a 
  36.  
  37. href=\"forum/'.$link.'\" class=\"tytul_newsa\">'.$result['topic_title'].'</a></b><hr width=\"90%\" align\"center\"><span 
  38.  
  39. class=\"news\">'.$text.'</span><div align=\"right\"><br /><span class=\"autor\">'.$author.' :: </span><a href=\"forum/'.$link.'\" 
  40.  
  41. class=\"autor\">Komentarzy: <span class=\"autor_red\">'.$result['topic_replies'].'</span></a></div></div>';
  42.  }
  43.  ?>


Może gdzieś popełniłem błąd?
4d3x
  1. <?php
  2. $dzial = '8';
  3.  
  4. $sql=&#092;"SELECT p.post_id, pt.post_id, pt.post_text, pt.bbcode_uid, t.topic_id, t.to
    p
  5. c_title, t.topic_first_post_id, t.forum_id, t.topic_replies, u.user_id,
  6.  
  7. u.username, u.user_posts, u.user_rank
  8.  FROM &#092;".TOPICS_TABLE.\" t, \".USERS_TABLE.\" u, \".POSTS_TABLE.\" p, \".POSTS_TEXT_TABLE.\" pt
  9.  WHERE t.forum_id = $dzial
  10.  AND t.topic_poster = u.user_id
  11.  AND t.topic_first_post_id = pt.post_id
  12.  AND t.topic_first_post_id = p.post_id
  13.  ORDER BY pt.post_id DESC&#092;";
  14.  $query=mysql_query($sql);
  15.  while(
  16. $result=mysql_fetch_assoc($query))
  17.  {
  18. $text = $result['post_text'];
  19. $text = bbcode_strip($text, $result['bbcode_uid']);
  20.  
  21. $text = str_replace(&#092;":)\", \"<img src=\"forum/images/smiles/icon_smile.gif\">\", $text);
  22. $text = str_replace(&#092;";)\", \"<img src=\"forum/images/smiles/icon_wink.gif\">\", $text);
  23. $text = str_replace(&#092;":P\", \"<img src=\"forum/images/smiles/icon_razz.gif\">\", $text);
  24. $text = str_replace(&#092;"X)\", \"<img src=\"forum/images/smiles/icon_twisted.gif\">\", $text);
  25. $text = str_replace(&#092;":D\", \"<img src=\"forum/images/smiles/icon_biggrin.gif\">\", $text);
  26. $text = str_replace(&#092;":(\", \"<img src=\"forum/images/smiles/icon_sad.gif\">\", $text);
  27. $text = str_replace(&#092;"->\", \"<img src=\"forum/images/smiles/icon_arrow.gif\">\", $text);
  28. $text = str_replace(&#092;";(\", \"<img src=\"forum/images/smiles/icon_cry.gif\">\", $text);
  29.  
  30. $link = append_sid('viewtopic.' . $phpEx . '?t=' . $result['topic_id']);
  31. if (strlen($text) > 1000){
  32. $text = substr($text, 0, 1000).'...[space][space] <a href=\"forum/'.$link.'\" class=\"wiecej\">Wiecej</a>';}
  33. $text = str_replace('
  34. ', '<br>', $text);
  35. $author = ' ';
  36. echo '<div style=\"text-align:justify; background:#FCFCFC; border: solid #CACACA 1px; padding:5px; margi
    n:5px; font-size:10pt\"><b><a
  37.  
  38. href=\"forum/'.$link.'\" class=\"tytul_newsa\">'.$result['topic_title'].'</a></b><hr width=\"90%\" align\"center\"><span
  39.  
  40. class=\"news\">'.$text.'</span><div align=\"right\"><br /><span class=\"autor\">'.$author.' :: </span><a href=\"forum/'.$link.'\"
  41.  
  42. class=\"autor\">Komentarzy: <span class=\"autor_red\">'.$result['topic_replies'].'</span></a></div></div>';
  43. }
  44. ?>


Powinno być dobrze
Louner
A tak biggrin.gif Działa świetnie, dziękuję smile.gif
aleksander
nie trzeba tyle razy wywoływac funkcję str_replac. Wystarczy jedno wywołaie z podaniem tablicy z tymi elementami.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.