I have a Shoutout Box written in PHP language.It doesnt have Smileys Support. How Can I Insert Smiley Support in it?
Some PHP that worked for me back in the day ;)
function Smilify(&$subject)
{
$smilies = array(
':|' => 'mellow',
':-|' => 'mellow',
':-o' => 'ohmy',
':-O' => 'ohmy',
':o' => 'ohmy',
':O' => 'ohmy',
';)' => 'wink',
';-)' => 'wink',
':p' => 'tongue',
':-p' => 'tongue',
':P' => 'tongue',
':-P' => 'tongue',
':D' => 'biggrin',
':-D' => 'biggrin',
'8)' => 'cool',
'8-)' => 'cool',
':)' => 'smile',
':-)' => 'smile',
':(' => 'sad',
':-(' => 'sad',
);
$sizes = array(
'biggrin' => 18,
'cool' => 20,
'haha' => 20,
'mellow' => 20,
'ohmy' => 20,
'sad' => 20,
'smile' => 18,
'tongue' => 20,
'wink' => 20,
);
$replace = array();
foreach ($smilies as $smiley => $imgName)
{
$size = $sizes[$imgName];
array_push($replace, '<img src="imgs/'.$imgName.'.gif" alt="'.$smiley.'" width="'.$size.'" height="'.$size.'" />');
}
$subject = str_replace(array_keys($smilies), $replace, $subject);
}
You can simply do:
<?php
echo str_replace(';)', '<img src="path/to/smile_image.gif" title=";)"/>', $message);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With