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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM