如何把字符在前端转成QQ表情?
就是前端输出一段诸如/:8-)之类的代码,
然后在前端把字符转成相应的QQ表情,请问有大神知道怎么样可以实现吗?
主角挚友丶
9 years, 7 months ago
Answers
既然是 代码 转 表情 ,那么肯定会有一个代码与表情(图片地址)的映射吧!
$array = array(
'/:8-' => '<img src="/path/to/face-1.jpg" />',
'/:9-' => '<img src="/path/to/face-2.jpg" />',
'/:10-' => '<img src="/path/to/face-3.jpg" />',
);
$comment = '你好啊 /:8-,你在哪里呢/:10-?';
echo strtr($comment, $array);
结果:
你好啊 <img src="/path/to/face-1.jpg" />,你在哪里呢 <img src="/path/to/face-3.jpg" />?
薙切爱丽丝
answered 9 years, 7 months ago
function replace_em(str){
str = str.replace(/\</g,'<');
str = str.replace(/\>/g,'>');
str = str.replace(/\n/g,'<br/>');
str = str.replace(/\[em_([0-9]*)\]/g,'<img src="face/$1.gif" border="0" style="width:20px; height:20px;" />');
str = str.replace(/\[img_([\d\D]*)\]/g,'<img src="upload/$1" border="0" style="width:20px; height:20px;" /><a href="upload/$1" target="_blank"></a>');
return str;
}
涼宫ハルヒ
answered 9 years, 7 months ago