Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] emoty w komentarzach, zielony
Sadu2
post 3.08.2007, 10:55:07
Post #1





Grupa: Zarejestrowani
Postów: 229
Pomógł: 13
Dołączył: 31.05.2007

Ostrzeżenie: (10%)
X----


Witam,
Mam oto taki kod:

  1. <?php
  2. function smilies($string)
  3.  {
  4.  
  5. $string = str_replace(":)", "<img src="gfx/emoty/smile.gif" alt=":)" />", $string);
  6. $string = str_replace(":(", "<img src="gfx/emoty/sad.gif" alt=":(" />", $string);
  7. $string = str_replace(";)", "<img src="gfx/emoty/wink.gif" alt=";)" />", $string);
  8. $string = str_replace(":D", "<img src="gfx/emoty/grin.gif" alt=":D" />", $string);
  9. $string = str_replace(":p", "<img src="gfx/emoty/pfft.gif" alt=":p" />", $string);
  10. $string = str_replace(":|", "<img src="gfx/emoty/frown.gif" alt=":|" />", $string);
  11. $string = str_replace(":o", "<img src="gfx/emoty/shock.gif" alt=":o" />", $string);
  12. $string = str_replace(":c", "<img src="gfx/emoty/cool.gif" alt=":c" />", $string);
  13. $string = str_replace(":@", "<img src="gfx/emoty/angry.gif" alt=":@" />", $string);
  14.  
  15. return $string;
  16.  }
  17. ?>


Zabardzo nieznam sie na php :( ale chciałbym aby wyświetlały mi sie emoty w komentarzach. Czy tak funkcja jest dobra? W którym miejscu mam ją umieścić aby działała? Dopiero sie ucze i prosze o wyrozumialość.

Pozdrawiam

Ten post edytował Sadu2 3.08.2007, 10:59:59
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
in5ane
post 3.08.2007, 11:07:07
Post #2





Grupa: Zarejestrowani
Postów: 1 335
Pomógł: 34
Dołączył: 9.11.2005
Skąd: Wrocław

Ostrzeżenie: (10%)
X----


Ja ci pomogę, poczekaj, zaraz coś napiszemy smile.gif

  1. <?php
  2.  
  3. function emots($txt){
  4.  
  5. $dane = Array
  6. (
  7. => Array
  8. (
  9. 'ikonka' => 'biggrin.gif',
  10. 'obraz' => 'emots/zeby.gif'
  11. ),
  12. => Array
  13. (
  14. 'ikonka' => 'questionmark.gif',
  15. 'obraz' => 'emots/pytajnik.gif'
  16. ),
  17. => Array
  18. (
  19. 'ikonka' => '!!',
  20. 'obraz' => 'emots/wykrzyknik.gif'
  21. ),
  22. => Array
  23. (
  24. 'ikonka' => 'tongue.gif',
  25. 'obraz' => 'emots/jezyk.gif'
  26. ),
  27. => Array
  28. (
  29. 'ikonka' => 'biggrin.gif',
  30. 'obraz' => 'emots/usmiech.gif'
  31. )
  32. );
  33.  
  34.  
  35. $txt = ' '.$txt.' ';
  36. if ( count( $dane ) > 0 )
  37. {
  38. foreach( $dane as $a => $row)
  39. {
  40. $kod = $row['ikonka'];
  41. $obraz = $row['obraz'];
  42. $kod = preg_quote($kod, "/");
  43. $txt = preg_replace( "!$kod!ei", "zmiana_emot('$kod', '$obraz')", $txt );
  44. }
  45. $txt = trim($txt);
  46. return $txt;
  47. }
  48. }
  49.  
  50.  
  51. function zmiana_emot($co="", $naco="")
  52. {
  53. $co = stripslashes($co);
  54. return "<img src="$naco" border=0">";
  55. }
  56.  
  57.  
  58. echo emotki ('biggrin.gif');
  59.  
  60.  
  61. ?>


i do folderu emots wbijasz emotki,
a w tym pliku masz u gory kilka testowych emotek dopisanych.

(skrypt nie jest moj, zaporzyczony z internetu)


--------------------
> > > Tworzenie stron < < <
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 13.06.2024 - 07:11