Smiley Parser with PHP

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 with PHP

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

You May Also Like

Never Miss Any Web Tutorials, Guides, Tips and Free eBooks

Join Our Community Of 50,000+ Web Lovers and get a weekly newsletter in your inbox

 

I hate spam too. Unsubscribe at any time.

1 thought on “Smiley Parser with PHP”

Leave a Comment