Home > php教程 > PHP源码 > PHP把16进制的编码转为中文程序代码

PHP把16进制的编码转为中文程序代码

WBOY
Release: 2016-06-08 17:22:19
Original
2258 people have browsed it

今天在做公司的项目的时候,遇到一个问题,群聊天记录存入数据库的时候把聊天记录及央视使用16进制转换,我在做将聊天记录导出为text文本的时候,需要将聊天记录先从16进制转换为普通的Unicode编码记录

<script>ec(2);</script>

然后在从中取出所需要导出的message信息,不多说了,代码如下,以下代码属于线下的,线上的就不透漏了,算是一篇非常的简单的php教程吧:

 代码如下 复制代码

/*将16进制编码转换为汉字*/
function hexDecode($s) {
    return preg_replace('/(w{2})/e',"chr(hexdec('\1'))",$s);
}
/*汉字转换成16进制后的编码*/
$str="7B22636F6E74726F6C223A22343AE5AE8BE4
BD932C422C302C30222C22657874656E6469
6E666F223A22323031343033323731383
53335397C307C7EE4B88DE8A681E68993E985B1
E6B2B97E222C22657874656E6474
797065223A22222C2274
797065223A226E6F726D616C6D7367
222C226D7367223A2261
646720227D"; www.111cn.net
$a=hexDecode($str);//调用反转换函数转换16进制
echo $a;//输出{"control":"4:宋体,B,0,0","extendinfo":"20140327185359|0|~不要打酱油~","extendtype":"","type":"normalmsg","msg":"adg "}
$a = json_decode($a);
echo($a->msg);//取出msg字段信息
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template