tags:

views:

161

answers:

3

I have a Shoutout Box written in PHP language.It doesnt have Smileys Support. How Can I Insert Smiley Support in it?

A: 

I would use javascript to check added shouts for combinations like ':-)' and replace them with an image of an smiley

Rob
Could be done in PHP as well. Search and replace.
Svish
+3  A: 

You can simply do:

<?php
echo str_replace(';)', '<img src="path/to/smile_image.gif" title=";)"/>', $message);
?>
Michał Mech
A: 
$smilies = array(":-)" => "smile.jpg", ";-P" => "thongue.jpg");

function replaceSmilies($str, $smilies) {

   $new_str = $str; 

   foreach($smilies as $tag => $image) {

     $new_str = str_replace($tag, "<img src='".$image."'/>", $new_str);

   }

   return $new_str; //return the new, updated string containing the smiley images

}

echo  replaceSmilies( 'Hello World! ;-P' , $smilies);
aSeptik
str_replace() accept arrays as a arguments. So You can do it in three lines without loop :P
Michał Mech
i know bro! but i need a loop for other reason! each element array have key => value
aSeptik