我有一个用PHP语言编写的Shoutout Box。它不支持表情符号。我该如何在其中插入表情符号支持?
从前曾经对我有用的一些 PHP 代码 ;)
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);
}
<?php
echo str_replace(';)', '<img src="path/to/smile_image.gif" title=";)"/>', $message);
?>
function parseString($string ) {
$my_smilies = array(
':aln' => '<img src="images/alien1.png" alt="" />',
':thk' => '<img src="images/annoyed.png" alt="" />',
':ang' => '<img src="images/angel.png" alt="" />',
':slp<' => '<img src="images/zzz.png" alt="" />',
':blnk' => '<img src="images/blanco.png" alt="" />',
':zip' => '<img src="images/zip_it.png" alt="" />',
':bor' => '<img src="images/boring.png" alt="" />',
);
return str_replace( array_keys($my_smilies), array_values($my_smilies), $string);
}
https://www.w3schools.com/charsets/ref_emoji_smileys.asp
例如:<p>我将显示😀</p>
结果:
我将显示