需要的材料:
php-emoji类库的下载地址:https://github.com/iamcal/php-emoji
代码示例:(该代码来自官网)
<?php
include('emoji.php'); # when you recieve text from a mobile device, convert it
# to the unified format.
//当你从移动设备里接收到信息,要将这些信息转为统一格式
//以下4个函数是从其他设备的格式转为统一格式 $data = emoji_docomo_to_unified($data); # DoCoMo devices
$data = emoji_kddi_to_unified($data); # KDDI & Au devices
$data = emoji_softbank_to_unified($data); # Softbank & pre-iOS6 Apple devices
$data = emoji_google_to_unified($data); # Google Android devices # when sending data back to mobile devices, you can
# convert back to their native format.
//以下4个函数是从统一格式转为其他设备能使用的格式 $data = emoji_unified_docomo($data); # DoCoMo devices
$data = emoji_unified_kddi($data); # KDDI & Au devices
$data = emoji_unified_softbank($data); # Softbank & pre-iOS6 Apple devices
$data = emoji_unified_google($data); # Google Android devices # when displaying data to anyone else, you can use HTML
# to format the emoji.
//从统一格式转为html格式 $data = emoji_unified_to_html($data); # if you want to use an editor(i.e:wysiwyg) to create the content,
# you can use html_to_unified to store the unified value. $data = emoji_html_to_unified(emoji_unified_to_html($data));
实现网页显示emoji表情的步骤:
一、下载php-emoji
二、在html文件里导入emoji.css文件
三、在脚本里导入emoji.php文件
完整代码:
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<!-- 导入emoji.css文件,切记一定要导入 -->
<link rel="stylesheet" type="text/css" href="./php_emoji/emoji.css">
</head>
<body>
<div id="chatContent">
<?php
//导入php_emoji类
include('./php_emoji/emoji.php');
//$data是emoji表情的数据
$data = emoji_unified_to_html($data);
//此时就能echo出emoji表情
echo $data;
?>
</div>
</body>
</html>
备注:一定要导入emoji.css文件