在我的评论框中,我想 如果用户写:)或:(或类似文本区域中的任何情绪,它在单击空格键后替换表情符号。
那么,如何实时将我的文本替换为表情符号。
我的PHP代码:提交后替换表情符号。
function smileys($text){
// Smiley to image
$smileys = array(
':)' => '<img src="smilies/smile.gif" border="0" alt="" />',
':D' => '<img src="smilies/smile.gif" border="0" alt="" />',
':(' => '<img src="smilies/sad.gif" border="0" alt="" />',
);
// Now you need find and replace
foreach($smileys as $search => $replace){
$text = preg_replace("#(?<='s|^)" . preg_quote($search) . "#", $replace, $text);
return $text;
}
}
echo''.smileys($description).'';
你可能正在寻找像这样的JavaScript解决方案:https://github.com/diy/jquery-emojiarea