Quantcast
Channel: W3lessons.info » Karthikeyan K | W3lessons.info
Viewing all articles
Browse latest Browse all 53

Smiley Parser with PHP

$
0
0

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


Viewing all articles
Browse latest Browse all 53

Trending Articles