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
?> |