Home  >  Article  >  Backend Development  >  PHP Chinese character transcoding example

PHP Chinese character transcoding example

WBOY
WBOYOriginal
2016-07-25 08:53:391767browse
  1. querys.json:
  2. {"cities":["u4e0au6d77","u4e1cu839e","u4e2du5c71","u4e3du6c34","u4e4cu9c81u6728u9f50","u4f5bu5c71","u 4fddu5b9a","u5170u5dde","u5317u4eac ","u5357u4eac","u5357u5b81","u5357u660c","u5357u901a","u8d35u9633","u8fdeu4e91u6e2f","u90a2u53f0","u90afu90f8","u90d1u5dde","u 91cdu5e86","u91d1u534e","u94f6u5ddd", "u9547u6c5f","u957fu6625","u957fu6c99","u9752u5c9b"]}
Copy code

2, php Chinese character transcoding file test.php

  1. header("content-Type: text/html; charset=Utf-8");

  2. set_time_limit(0); //Set the allowed execution of a program The number of seconds, 0 is the maximum limit

  3. $file = "querys.json";

  4. $content = file_get_contents($file);
  5. echo $content."
    " ;

  6. function replace_unicode_escape_sequence($match){

  7. return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
  8. }
  9. $str = preg_replace_callback('/\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $content);
  10. echo $str;
  11. ?>

Copy code


Statement:
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