Emoticons are very popular in the Internet these days. It seems like now every forums, mailing lists and guestbook support emoticons in their pages. If you write such applications, why not add them too? The basic concept is simple, all you need to do is replace smiley tags with the appropriate icons. For example, replace all :) with <img src="img/smile.gif" border="0" alt=":)" />
Here's a simple example to convert smileys to emoticons. You can get the icons from Yahoo Messenger and rename the icons like smile.gif, sad.gif, angry.gif, etc.
The function above will convert smiley tags to emoticons for the given text. Wanna see some demo? See smiley2emoticon s in action!
Here's a simple example to convert smileys to emoticons. You can get the icons from Yahoo Messenger and rename the icons like smile.gif, sad.gif, angry.gif, etc.
Code:
<?php
function smiley2emoticons($text)
{
$tags = array
(
';)' => '__winking.gif__;)__',
':D' => '__biggrin.gif__:D__',
':-/' => '__confused.gif__:-/__',
'8->' => '__daydreaming.gif__8->__',
':P' => '__tongue.gif__:P__',
':-*' => '__kiss.gif__:-*__',
':-O' => '__surprise.gif__:-O__',
'X(' => '__angry.gif__X(__',
'B-)' => '__cool.gif__B-)__',
'>:)' => '__devil.gif__>:)__',
':((' => '__crying.gif__:((__',
':))' => '__laughing.gif__:))__',
':|' => '__straightface.gif__:|__',
'=))' => '__rollingonthefloor.gif__=))__',
':-c' => '__callme.gif__:-c__',
':)]' => '__onthephone.gif__:)]__',
':-?' => '__thinking.gif__:-?__',
'#o' => '__doh.gif__#o__',
':-w' => '__waiting.gif__:-w__',
':)' => '__smile.gif__:)__',
':-)' => '__smile.gif__:)__',
':(' => '__sad.gif__:(__',
':-(' => '__sad.gif__:(__',
'(:|' => '__yawn.gif__(:|__'
);
$new = strtr($text, $tags);
$new = preg_replace("/__([^_]*)__([^_]*)__/", "<img src=\"img/$1\" border=\"0\" alt=\"$2\" />", $new);
return($new);
}
?>
Comment