1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

マルチバイト文字がそのままのjson_encode

Posted at

print json_jap(array("jap"=>"あいうえお","intType"=>1234567890,"strInt"=>"1234567890"));
{"jap":"あいうえお","intType":1234567890,"strInt":"1234567890"}

json_jap.php
<?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;
}
?>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?