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
2010-05-04 09:57:30
Could be done in PHP as well. Search and replace.
Svish
2010-05-04 10:05:52
+3
A:
You can simply do:
<?php
echo str_replace(';)', '<img src="path/to/smile_image.gif" title=";)"/>', $message);
?>
Michał Mech
2010-05-04 10:07:04
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
2010-05-04 10:36:01
str_replace() accept arrays as a arguments. So You can do it in three lines without loop :P
Michał Mech
2010-05-04 12:32:14
i know bro! but i need a loop for other reason! each element array have key => value
aSeptik
2010-05-04 13:03:01