Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php]emoty czemu nie dziala?
kuba749
post 24.02.2007, 20:04:56
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 30.07.2006
Skąd: Jasło

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


napisałem skrypt do zamiany tekstu na emotikony ale nie działa. Co w nim jest nie tak??
  1. <?
  2. function emots($text){
  3. $emots[':*']='<img scr="./emots/cmok.gif">';
  4. $emots['<glupek>']='<img scr="./emots/glupek.gif">';
  5. $emots['<idiota>']='<img scr="./emots/glupek2.gif">';
  6. $emots['<killer>']='<img scr="./emots/killer.gif">';
  7. $emots['<krzyk>']='<img scr="./emots/krzyk.gif">';
  8. $emots['<lol>']='<img scr="./emots/lol.gif">';
  9. $emots['<paker>']='<img scr="./emots/paker.gif">';
  10. $emots['<niedowiarek>']='<img scr="./emots/puknijsie.gif">';
  11. $emots['<sex>']='<img scr="./emots/sex.gif">';
  12. $emots['<stop>']='<img scr="./emots/stop.gif">';
  13. $emots['biggrin.gif']='<img scr="./emots/zeby.gif">';
  14. $emots[':[']='<img scr="./emots/zly.gif">';
  15. $emots['<bezradny>']='<img scr="./emots/bezradny.gif">';
  16. $emots['<buziak>']='<img scr="./emots/buziak.gif">';
  17. $emots['<cwaniak>']='<img scr="./emots/cwaniak.gif">';
  18. $emots['<blee>']='<img scr="./emots/dobani.gif">';
  19. $emots['<dokuczacz>']='<img scr="./emots/dokuczacz.gif">';
  20. $emots['<haha>']='<img scr="./emots/haha.gif">';
  21. $emots['<hura>']='<img scr="./emots/hura.gif">';
  22. $emots['tongue.gif']='<img scr="./emots/jezyk.gif">';
  23. $emots['<nie>']='<img scr="./emots/nie.gif">';
  24. $emots['<nerwus>']='<img scr="./emots/nerwus.gif">';
  25. $emots['<rotfl>']='<img scr="./emots/rotfl.gif">';
  26. $emots['<wysmiewacz>']='<img scr="./emots/wysmiewacz.gif">';
  27. $emots[';))']='<img scr="./emots/wesoly.gif">';
  28. $emots['<dupa>']='<img scr="./emots/dupa.gif">';
  29. $emots['<faja>']='<img scr="./emots/faja.gif">';
  30. $emots['<ganja>']='<img scr="./emots/genja.gif">';
  31. $emots['<piwo>']='<img scr="./emots/piwo.gif">';
  32. $emots['<pomocy>']='<img scr="./emots/pomocy.gif">';
  33. $tekst=str_replace($emots, $emots, $tekst);
  34. }
  35. echo emots(":D biggrin.gif");
  36. ?>
Go to the top of the page
+Quote Post
kriqs
post 24.02.2007, 20:11:03
Post #2





Grupa: Zarejestrowani
Postów: 148
Pomógł: 0
Dołączył: 31.05.2006

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


http://pl2.php.net/str_replace
troche zle dobrales tablice i wszystko jasne smile.gif


--------------------
Pozdrawiam
kriqs

mam nadzieje ze pomoglem :)
Go to the top of the page
+Quote Post
kuba749
post 24.02.2007, 21:41:47
Post #3





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 30.07.2006
Skąd: Jasło

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


Zrobiłem teraz tak i dalej nic
  1. <?
  2. function emots($text){
  3. $emots=array(
  4. ':*' => '<img scr="./emots/cmok.gif">',
  5. '<glupek>'=>'<img scr="./emots/glupek.gif">',
  6. '<idiota>'=>'<img scr="./emots/glupek2.gif">',
  7. '<killer>'=>'<img scr="./emots/killer.gif">',
  8. '<krzyk>'=>'<img scr="./emots/krzyk.gif">',
  9. '<lol>'=>'<img scr="./emots/lol.gif">',
  10. '<paker>'=>'<img scr="./emots/paker.gif">',
  11. '<niedowiarek>'=>'<img scr="./emots/puknijsie.gif">',
  12. '<sex>'=>'<img scr="./emots/sex.gif">',
  13. '<stop>'=>'<img scr="./emots/stop.gif">',
  14. 'biggrin.gif'=>'<img scr="./emots/zeby.gif">',
  15. ':['=>'<img scr="./emots/zly.gif">',
  16. '<bezradny>'=>'<img scr="./emots/bezradny.gif">',
  17. '<buziak>'=>'<img scr="./emots/buziak.gif">',
  18. '<cwaniak>'=>'<img scr="./emots/cwaniak.gif">',
  19. '<blee>'=>'<img scr="./emots/dobani.gif">',
  20. '<dokuczacz>'=>'<img scr="./emots/dokuczacz.gif">',
  21. '<haha>'=>'<img scr="./emots/haha.gif">',
  22. '<hura>'=>'<img scr="./emots/hura.gif">',
  23. 'tongue.gif'=>'<img scr="./emots/jezyk.gif">',
  24. '<nie>'=>'<img scr="./emots/nie.gif">',
  25. '<nerwus>'=>'<img scr="./emots/nerwus.gif">',
  26. '<rotfl>'=>'<img scr="./emots/rotfl.gif">',
  27. '<wysmiewacz>'=>'<img scr="./emots/wysmiewacz.gif">',
  28. ';))'=>'<img scr="./emots/wesoly.gif">',
  29. '<dupa>'=>'<img scr="./emots/dupa.gif">',
  30. '<faja>'=>'<img scr="./emots/faja.gif">',
  31. '<ganja>'=>'<img scr="./emots/genja.gif">',
  32. '<piwo>'=>'<img scr="./emots/piwo.gif">',
  33. '<pomocy>'=>'<img scr="./emots/pomocy.gif">');
  34. $tekst=str_replace($emots, $emots, $tekst);
  35. }
  36. echo emots(":D biggrin.gif");
  37. ?>
Go to the top of the page
+Quote Post
jarrod
post 24.02.2007, 23:51:51
Post #4





Grupa: Zarejestrowani
Postów: 312
Pomógł: 9
Dołączył: 14.10.2006
Skąd: warszawa

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


Spróbuj:
  1. <?php
  2. $emots = str_replace( 
  3. array( 
  4. ':*','<glupek>'
  5. ),
  6. array( 
  7. '<img scr="./emots/cmok.gif">','<img scr="./emots/glupek.gif">'
  8. ),
  9. $text
  10. );
  11. ?>

lub
  1. <?php
  2. $emoty = array(':*','<glupek>');
  3. $obrazki = array( '<img scr="./emots/cmok.gif">','<img scr="./emots/glupek.gif">');
  4. $emots = str_replace( $emoty, $obrazki, $text);
  5. ?>

Oczywiście oba zapisy są dokłądnie tym samym winksmiley.jpg

Ten post edytował jarrod 24.02.2007, 23:52:16
Go to the top of the page
+Quote Post
envp
post 24.02.2007, 23:57:16
Post #5





Grupa: Zarejestrowani
Postów: 359
Pomógł: 1
Dołączył: 16.04.2006
Skąd: Łódź

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


  1. <?php
  2. //zamiast ostatniej linijki
  3. foreach($emots as $bez_emoty => $z_emota)
  4. {
  5. $text = str_replace($bez_emoty, $z_emota, $text);
  6. }
  7.  
  8. return $text;
  9. ?>
Go to the top of the page
+Quote Post
Mary$
post 24.02.2007, 23:57:35
Post #6





Grupa: Zarejestrowani
Postów: 113
Pomógł: 1
Dołączył: 19.02.2007
Skąd: 3city

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


spróbuj z foreach" title="Zobacz w manualu PHP" target="_manual
  1. <?php
  2. function emotki($string)
  3. {
  4. $emoty = array(
  5. ":)" => "happy.gif",
  6. ":(" => "sad.gif"
  7. );
  8. foreach($emoty as $tekst => $obrazek) $string = str_replace($tekst,'<img src="images/'.$obrazek.'" />',$string); 
  9. return $string;
  10. }
  11. ?>


--------------------
Nie ma rzeczy niemożliwych - są tylko czasochłonne i mało opłacalne.
Go to the top of the page
+Quote Post
siemakuba
post 25.02.2007, 11:59:50
Post #7





Grupa: Przyjaciele php.pl
Postów: 1 112
Pomógł: 20
Dołączył: 10.04.2005

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


W pierwszym podanym przez ciebie kodzie,
tę linię:
  1. <?php
  2. $tekst=str_replace($emots, $emots, $tekst);
  3. ?>

zamień na:
  1. <?php
  2. $tekst=str_replace(array_keys($emots), $emots, $tekst);
  3. ?>


pozdr.
Go to the top of the page
+Quote Post

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: 24.07.2025 - 17:39