Text to Smileys

By F*U*R*B*Y* on Apr 10, 2006

okay just upload it to any website, and have $msg at everything you want to have a smiley face. YOU MUST HAVE THE SMILEY FILE NAME ON YOUR WEBSERVER/WEBSITE THE TEXT HAS TO BE THE SAME :p won't be the same as :P


function smiley($msg) { 
      $msg = ereg_replace("!","<img src=!.png alt=\"!\" >", $msg); 
      $msg = ereg_replace(":D","<img src=laugh.gif alt=\":D\" >", $msg); 
      $msg = ereg_replace(":p","<img src=tongue.gif alt=\":p\" >", $msg); 
      return $msg; 

 $msg = "Hi ! <br> Hello :D<br> Heheh :p"; 
 echo smiley($msg); 



Sign in to comment.
MarioErmando   -  May 30, 2012

Works perfectly! :)

Chat-Police   -  Jun 20, 2007

PHP newbie here....

this looks like it would be great for my site... I\'ve tried to get it runnng with no luck. couple of questions

1) what do i call the php file?
2) how do you get it to work lol. ie do you type \"$msg = :D\" to replace text to smiley.

could you explain a little please for me sorry

thanks C-P

cooolstar   -  Jun 21, 2006

this is good for beginners.
but also it was included in php manual
Hawkee asked for arrays, i also used, but newbei must have an idea to use replace function
any ways it nice to paste here

Earl   -  Apr 11, 2006

pretty simple but good work

Hawkee   -  Apr 10, 2006

Now you can let it take in an array of smiley shortcuts and images. Just set up a loop that extracts the smilies and image URLs from a table in mySQL.

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.