Skip to content

Instantly share code, notes, and snippets.

@fushihara
Created April 26, 2012 05:42
Show Gist options
  • Save fushihara/2496307 to your computer and use it in GitHub Desktop.
Save fushihara/2496307 to your computer and use it in GitHub Desktop.
マルチバイト文字がそのままのjson_encode ref: http://qiita.com/items/71e1ec7e52b76f467d29
<?php
function json_jap($obj){
$str=json_encode($obj);
$str=preg_replace_callback('{\\\\u([0-9a-f]{4})}',function($m){return mb_convert_encoding(hex2bin($m[1]),'UTF-8','UTF-16');},$str);
$str=str_replace(['\/','&gt;','&lt;','&apos;','&amp;'],['/','>','<','\'','&'],$str);
return $str;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment