使用php-emoji類讓網頁顯示emoji表情

須要的材料:php

  php-emoji類庫的下載地址:https://github.com/iamcal/php-emojicss

代碼示例:(該代碼來自官網)html

 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表情的步驟:git

  1、下載php-emojigithub

  二、在html文件裏導入emoji.css文件函數

  3、在腳本里導入emoji.php文件ui

  完整代碼:google

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

相關文章
相關標籤/搜索