Home > Backend Development > PHP Tutorial > Solve the problem of php json_encode Chinese transcoding and garbled characters

Solve the problem of php json_encode Chinese transcoding and garbled characters

WBOY
Release: 2016-07-25 09:13:20
Original
1212 people have browsed it

Example, php json_encode Chinese transcoding and garbled code problems.

  1. // Prevent json Chinese transcoding

  2. function jsonEncodeWithCN($data) {
  3. return preg_replace("/\u([0-9a-f]{4} )/ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '$1'))", json_encode($data));
  4. }

  5. < p>$arr = array('a'=>'test', b=>'hello');

  6. echo jsonEncodeWithCN($arr);

Copy code


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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template