[英]How to real time replace text with emoticons in my php comment box
In my comment box I want to If user write :) or :( or something like any emotion in textarea, It replace emoticon just after click on space key. 在我的注释框中,我想如果用户写:)或:(或类似文本区域中的任何情感,它会在单击空格键后立即替换图释。
So, how to real time replace my text to emoticons. 因此,如何实时将我的文字替换为表情符号。
my php code: which replace emoticon after submit. 我的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.