javascript - 如何把字符在前端转成QQ表情?

WBOY
Release: 2016-06-06 20:29:00
Original
1650 people have browsed it

就是前端输出一段诸如/:8-)之类的代码,
然后在前端把字符转成相应的QQ表情,请问有大神知道怎么样可以实现吗?

回复内容:

就是前端输出一段诸如/:8-)之类的代码,
然后在前端把字符转成相应的QQ表情,请问有大神知道怎么样可以实现吗?

既然是 代码表情,那么肯定会有一个代码与表情(图片地址)的映射吧!

<code class="php">$array = array(
    '/:8-' => '<img  src="/path/to/face-1.jpg" alt="javascript - 如何把字符在前端转成QQ表情?" >',
    '/:9-' => '<img  src="/path/to/face-2.jpg" alt="javascript - 如何把字符在前端转成QQ表情?" >',
    '/:10-' => '<img  src="/path/to/face-3.jpg" alt="javascript - 如何把字符在前端转成QQ表情?" >',
);

$comment = '你好啊 /:8-,你在哪里呢/:10-?';

echo strtr($comment, $array);
</code>
Copy after login

结果:

<code class="php">你好啊 <img  src="/path/to/face-1.jpg" alt="javascript - 如何把字符在前端转成QQ表情?" >,你在哪里呢 <img  src="/path/to/face-3.jpg" alt="javascript - 如何把字符在前端转成QQ表情?" >?</code>
Copy after login

正则或者字符串替换替换成img图片地址。。。

function replace_em(str){

<code>str = str.replace(/\,'<');
str = str.replace(/\>/g,'>');
str = str.replace(/\n/g,'<br>');
str = str.replace(/\[em_([0-9]*)\]/g,'<img  src="face/%241.gif" border="0"   style="max-width:90%" alt="javascript - 如何把字符在前端转成QQ表情?" >');

str = str.replace(/\[img_([\d\D]*)\]/g,'<img  src="upload/%241" border="0"   style="max-width:90%" alt="javascript - 如何把字符在前端转成QQ表情?" ><a href="upload/%241" target="_blank"></a>');

return str;</code>
Copy after login

}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!