Skip to content

Instantly share code, notes, and snippets.

@tassoevan
Forked from hayatravis/json_enconde_jp.php
Last active August 29, 2015 14:27
Show Gist options
  • Save tassoevan/c8a9fc9b61b5446e41d1 to your computer and use it in GitHub Desktop.
Save tassoevan/c8a9fc9b61b5446e41d1 to your computer and use it in GitHub Desktop.
json_encode($array,JSON_UNESCAPED_UNICODE) For PHP5.3. Except json encoding japanese For php5.3. php5.3のjson_encodeで日本語をエンコードさせない関数。
function json_encode_jp($array) {
return preg_replace_callback(
'/\\\\u([0-9a-zA-Z]{4})/',
function ($matches) {
return mb_convert_encoding(pack('H*',$matches[1]),'UTF-8','UTF-16');
},
json_encode($array)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment