Today I am going to share How to make a smiley parser in PHP with few lines of code.
A simple array with key as smiley symbol & value as image is used to parse a smiley using php’s str_replace function
These little tricks will spice up your IM conversations and show friends how you feel.
Smiley Parser PHP Code
$smiles = array(
'xD' => 'devil.png',
'>:)' => 'devil.png',
'x(' => 'angry.png',
':((' => 'cry.png',
':*' => 'kiss.png',
':))' => 'laugh.png',
':D' => 'laugh.png',
':-D' => 'laugh.png',
':x' => 'love.png',
'(:|' => 'sleepy.png',
':)' => 'smile.png',
':-)' => 'smile.png',
':(' => 'sad.png',
':-(' => 'sad.png',
';)' => 'wink.png',
';-)' => 'wink.png'
);
foreach($smiles as $key => $img) {
$msg = str_replace($key, '<img src="emotions/'.$img.'" height="18" width="18" />', $msg);
}
echo $msg;
Please don’t forget to share and subscribe to latest updates of the blog. Comments and feedbacks are always welcome!
Thanks
🙂