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


    需要的材料:

      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文件

  • 相关阅读:
    jQuery 如何存储,获取和删除 Cookies
    mysql调用存储过程出现Illegal mix of collations错误
    vim IDE
    android 播放Raw文件夹下的音乐文件
    7种形式的Android Dialog使用举例
    Chronometer 计时器使用
    获取屏幕,适应屏幕
    android 碎片
    安卓开发者必备的42个链接
    自定义TabActivity,TabActivity的美化
  • 原文地址:https://www.cnblogs.com/sustudy/p/4463509.html
Copyright © 2020-2023  润新知