irwan

Replace emoticons with smileys

Apr 18th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?PHP
  2. // this is the funktion
  3. function smile_replace($text) {
  4.  // Here is the array with the smilies, it can be extended
  5.  $smileys = array (
  6.  ':)' =>'<img src="smileys/smile.gif" alt="Smile" width="20" height="20" border="0">',
  7.  ':o' => '<img src="smileys/dazed.gif" alt="Dazed" width="20" height="20" border="0">',
  8.  ';)' => '<img src="smileys/wink.gif" alt="Wink" width="20" height="20" border="0">',
  9.  ':(' => '<img src="smileys/sad.gif" alt="Sad" width="20" height="20" border="0">',
  10.  ':angel:' => '<img src="smileys/angel.gif" alt="Angel" width="20" height="20" border="0">',
  11.  ':devil:' => '<img src="smileys/devil.gif" alt="Devil" width="20" height="20" border="0">',
  12.  ':up:' => '<img src="smileys/up.gif" alt="Thumb up" width="20" height="20" border="0">'
  13.  );
  14.  // Here are the smileys replaced
  15.  $text = str_replace (array_keys($smileys), array_values($smileys), $text);
  16.  return $text;
  17. }
  18. // This is an example text
  19. $mytext = ":up: This is a simple guestbook entry with smileys :) ;) :angel:";
  20. // and so we use the function
  21. echo smile_replace($mytext);
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment