Ads

March 28, 2014

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.

  For info or contact: facebook @nkondal1 and twitter @nkondal1


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;

No comments:

Most Popular Posts