Skip to content

Instantly share code, notes, and snippets.

@fushihara
Created April 6, 2012 12:23
Show Gist options
  • Save fushihara/2319296 to your computer and use it in GitHub Desktop.
Save fushihara/2319296 to your computer and use it in GitHub Desktop.
日本語が読めるjsonエンコード
<?php
function json_jap($str){
//"\u3042\u3044\u3046\u3048\u304a" → "あいうえお"
$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