• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

使用php-emoji类让网页显示emoji表情

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

需要的材料:

  php-emoji类库的下载地址:https://github.com/iamcal/php-emoji

代码示例:(该代码来自官网)

 1 <?php
 2     include('emoji.php');
 3 
 4     # when you recieve text from a mobile device, convert it
 5     # to the unified format.
 6     //当你从移动设备里接收到信息,要将这些信息转为统一格式
 7     //以下4个函数是从其他设备的格式转为统一格式
 8 
 9     $data = emoji_docomo_to_unified($data);   # DoCoMo devices
10     $data = emoji_kddi_to_unified($data);     # KDDI & Au devices
11     $data = emoji_softbank_to_unified($data); # Softbank & pre-iOS6 Apple devices
12     $data = emoji_google_to_unified($data);   # Google Android devices
13 
14 
15     # when sending data back to mobile devices, you can
16     # convert back to their native format.
17     //以下4个函数是从统一格式转为其他设备能使用的格式
18 
19     $data = emoji_unified_docomo($data);   # DoCoMo devices
20     $data = emoji_unified_kddi($data);     # KDDI & Au devices
21     $data = emoji_unified_softbank($data); # Softbank & pre-iOS6 Apple devices
22     $data = emoji_unified_google($data);   # Google Android devices
23 
24 
25     # when displaying data to anyone else, you can use HTML
26     # to format the emoji.
27     //从统一格式转为html格式
28 
29     $data = emoji_unified_to_html($data);
30 
31     # if you want to use an editor(i.e:wysiwyg) to create the content, 
32     # you can use html_to_unified to store the unified value.
33 
34     $data = emoji_html_to_unified(emoji_unified_to_html($data));

 

实现网页显示emoji表情的步骤:

  一、下载php-emoji

  二、在html文件里导入emoji.css文件

  三、在脚本里导入emoji.php文件

  完整代码:

 1 <!doctype html>
 2 <html>
 3     <head>
 4         <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
 5         <!-- 导入emoji.css文件,切记一定要导入 -->
 6         <link rel="stylesheet" type="text/css" href="./php_emoji/emoji.css">
 7     </head>
 8     <body>
 9         <div id="chatContent">
10             <?php
11                 //导入php_emoji类
12                 include('./php_emoji/emoji.php');
13                 //$data是emoji表情的数据
14                 $data = emoji_unified_to_html($data);
15                 //此时就能echo出emoji表情
16                 echo $data;
17             ?>
18         </div>
19     </body>
20 </html>

 

备注:一定要导入emoji.css文件

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
关于php的一些小谈发布时间:2022-07-10
下一篇:
php多态发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap