PHP converts hexadecimal encoding into Chinese program code-PHP source code

Source: Internet
Author: User
Today, when I was working on a company project, I encountered a problem. When the group chat records were stored in the database, I converted the chat records and CCTV's hexadecimal conversion, when I export a chat record as text, I need to convert the chat record from hexadecimal to a normal Unicode encoding record. Today, when I am working on a company project, A problem occurs: when the group chat records are stored in the database, the chat records and CCTV are converted in hexadecimal notation. When I export the chat records as text, the chat record needs to be first converted from hexadecimal to normal Unicode encoding record

Script ec (2); script

Then, extract the message to be exported from it. The Code is as follows. The following code is offline and will not be disclosed online, it is a very simple php Tutorial:

The Code is as follows:

/* Convert hexadecimal encoding to Chinese characters */
Function hexDecode ($ s ){
Return preg_replace ('/(w {2})/E', "chr (hexdec (' \ 1')", $ s );
}
/* Convert Chinese characters to hexadecimal encoding */
$ Str = "7B22636F6E74726F6C223A22343AE5AE8BE4
BD932C422C302C30222C22657874656E6469
6e666f223a22323031321333323731383
53335da-c307c7ee4b88de8a681e68993e985b1
E6B2B97E222C22657874656E6474
797065223A22222C2274
797065223a226e6fda-d616c6d7367
222c226d7415223a2261
646720227D "; www.111cn.net
$ A = hexDecode ($ str); // call the anti-conversion function to convert the hexadecimal value
Echo $ a; // output {"control": "4:, B, 20140327185359", "extendinfo": "| 0 | ~ Do not make soy sauce ~ "," Extendtype ":" "," type ":" normalmsg "," msg ":" adg "}
$ A = json_decode ($ );
Echo ($ a-> msg); // retrieve msg Field Information
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.