Rumah > pembangunan bahagian belakang > tutorial php > php汉字转码示例

php汉字转码示例

WBOY
Lepaskan: 2016-07-25 08:53:39
asal
1798 orang telah melayarinya
  1. querys.json:
  2. {"cities":["\u4e0a\u6d77","\u4e1c\u839e","\u4e2d\u5c71","\u4e3d\u6c34","\u4e4c\u9c81\u6728\u9f50","\u4f5b\u5c71","\u4fdd\u5b9a","\u5170\u5dde","\u5317\u4eac","\u5357\u4eac","\u5357\u5b81","\u5357\u660c","\u5357\u901a","\u8d35\u9633","\u8fde\u4e91\u6e2f","\u90a2\u53f0","\u90af\u90f8","\u90d1\u5dde","\u91cd\u5e86","\u91d1\u534e","\u94f6\u5ddd","\u9547\u6c5f","\u957f\u6625","\u957f\u6c99","\u9752\u5c9b"]}
复制代码

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

  1. php

  2. header("content-Type: text/html; charset=Utf-8");
  3. set_time_limit(0); //设定一个程式所允许执行的秒数,0为最大限度
  4. $file = "querys.json";

  5. $content = file_get_contents($file);
  6. echo $content."
    ";
  7. function replace_unicode_escape_sequence($match){

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


Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan