首页 > Web开发 > 详细

PHP json_encode中日语问题

时间:2015-07-30 10:56:52      阅读:490      评论:0      收藏:0      [点我收藏+]
<?php
header(‘Content-type:text/html;charset=utf-8‘);
$s = array(‘message‘=>‘4月以降、遺体の捜索活動が続けられてきたが‘);

$sJSON = json_encode($s);

var_dump($sJSON); // 会转换成16进制
var_dump(json_decode($sJSON));



$sJSON = json_encode($s, defined(‘JSON_UNESCAPED_UNICODE‘) ? JSON_UNESCAPED_UNICODE : 0);
if (!defined(‘JSON_UNESCAPED_UNICODE‘) && function_exists(‘mb_convert_encoding‘)) {
  $sJSON = preg_replace_callback(
    ‘~\\\\u([0-9a-f]{4})~i‘,
    create_function(‘$aMatches‘, ‘return mb_convert_encoding(pack("H*", $aMatches[1]), "UTF-8", "UTF-16");‘),
    $sJSON);
}

var_dump($sJSON);
var_dump(json_decode($sJSON));

  

PHP json_encode中日语问题

原文:http://www.cnblogs.com/adtuu/p/4688297.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!