Skip to content

Instantly share code, notes, and snippets.

@Anye
Created July 23, 2014 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anye/22055ddd55494d48d504 to your computer and use it in GitHub Desktop.
Save Anye/22055ddd55494d48d504 to your computer and use it in GitHub Desktop.
json_encode 显示中文
function __json_encode( $obj )
{
if( defined( 'JSON_UNESCAPED_UNICODE' ) ){ // >= php 5.4
return json_encode( $obj, JSON_UNESCAPED_UNICODE );
} else {
return preg_replace( "/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", json_encode( $obj ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment