php漢字轉碼範例

WBOY
發布: 2016-07-25 08:53:39
原創
1770 人瀏覽過
  1. querys.json:
  2. {"cities":["u4e0au6d77","u4e1cu839e","u4e2du5c71","u4e3du6c34","u4e4cu9c81u6728u9f50","u4f5bu5c71","u4fddu5b9a","u5170u5dde","u5317u4eac","u5357u4eac","u5357u5b81","u5357u660c","u5357u901a","u8d35u9633","u8fdeu4e91u6e2f","u90a2u53f0","u90afu90f8","u90d1u5dde","u91cdu5e86","u91d1u534e","u94f6u5ddd","u9547u6c5f","u957fu6625","u957fu6c99","u9752u5c9b"]}
复制代码

2,php汉字转码文件 test.php

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

  2. set_time_limit(0); //设定一个程式所允许执行的秒数,0为最大限度

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

复制代码


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板