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;

View Live Demo & Download

Please don’t forget to share and subscribe to latest updates of the blog. Comments and feedbacks are always welcome!

Thanks

If you enjoyed this article, Get email updates (It’s Free)
http://w3lessons.info/wp-content/uploads/2013/08/Smiley-Parser-with-PHP.pnghttp://w3lessons.info/wp-content/uploads/2013/08/Smiley-Parser-with-PHP-150x150.pngKarthikeyan KPHPnew techniques,php,tips & tricks
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 functionThese little tricks  will spice up your IM conversations and...