您的位置:首页 > 编程语言 > PHP开发

本地win7 把数组写入 txt 文本日志 json_encode转换中文,需要加上JSON_UNESCAPED_UNICODE 不适用unicode --仅仅支持php5.4以后

2016-11-25 11:56 836 查看
json_encode 改进 为 json_encode_ex


function json_encode_ex($value)
{
  if (version_compare(PHP_VERSION, '5.4.0', '<')){

  $str = json_encode($value);
  $str = preg_replace_callback("#\\\u([0-9a-f]{4})#i", function ($matchs) {
  return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1]));
  }, $str);
  return $str;
  } else {
  return json_encode($value, JSON_UNESCAPED_UNICODE);
  }
}

function mylog1($word){
  if(YII_DEBUG){
  $file = 'mylog1.txt';
  file_put_contents($file,'执行时间'.date('Y-m-d H:i:s',time())."\n".$word."\n\n",FILE_APPEND);
  }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: