web_master Posted October 2, 2007 Share Posted October 2, 2007 Hi, People write text in shout box (pure PHP). When reload the text from dBase I want to change the basic "smiles" to icons. Example: Hello, my name is Georg : ) - change to Hello, my name is Georg ... Thanx in advanced Quote Link to comment https://forums.phpfreaks.com/topic/71541-solved-smilies-in-text/ Share on other sites More sharing options...
trq Posted October 2, 2007 Share Posted October 2, 2007 An example. <?php $s = "this is some text with a smilie face "; echo str_replace("","<img src='smilie.gif'>",$s); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71541-solved-smilies-in-text/#findComment-360202 Share on other sites More sharing options...
web_master Posted October 2, 2007 Author Share Posted October 2, 2007 An example. <?php $s = "this is some text with a smilie face "; echo str_replace("","<img src='smilie.gif'>",$s); ?> OK this is a 1 string to replace, but how can I change a more than 1 strings in 1 text? Quote Link to comment https://forums.phpfreaks.com/topic/71541-solved-smilies-in-text/#findComment-360204 Share on other sites More sharing options...
trq Posted October 2, 2007 Share Posted October 2, 2007 <?php $s = "this is some text with a smilie face "; $s = str_replace("","<img src='smilie.gif'>", $s); $s = str_replace("","<img src='frown.gif'>", $s); echo $s; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71541-solved-smilies-in-text/#findComment-360207 Share on other sites More sharing options...
wildteen88 Posted October 2, 2007 Share Posted October 2, 2007 It'll be better if you use an array: function parse_smilies($txt) { $smilies_symb = array('', '', ''); $smilies_html = array('<img src="smilie.gif">', '<img src="sad.gif">', '<img src="wink.gif">'); $txt = str_replace($smilies_symb, $smilies_html, $txt); return $txt; } $s = "this is some text with a smilie face "; $s = parse_smilies($s); echo $s; Quote Link to comment https://forums.phpfreaks.com/topic/71541-solved-smilies-in-text/#findComment-360212 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 another example <?php $code[] = ""; $img[]="<img src='frown.gif'>"; $code[] = ""; $img[]="<img src='happy.gif'>"; $code[] = ""; $img[]="<img src='poke.gif'>"; $s = "this is some text with a smilie face "; $s = str_replace($code, $img, $s); echo $s; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71541-solved-smilies-in-text/#findComment-360215 Share on other sites More sharing options...
web_master Posted October 2, 2007 Author Share Posted October 2, 2007 Its workin! Thanx for everybody!!!! Quote Link to comment https://forums.phpfreaks.com/topic/71541-solved-smilies-in-text/#findComment-360217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.