Skip to content

Instantly share code, notes, and snippets.

@branchzero
Last active August 29, 2015 14:19
Show Gist options
  • Save branchzero/eb908ff4341a4741e7fe to your computer and use it in GitHub Desktop.
Save branchzero/eb908ff4341a4741e7fe to your computer and use it in GitHub Desktop.
Array To Json (Any Charset Auto-Convert To UTF-8)
<?php
echo encode_json(array('啊'=>'白'));
function encode_json($str) {
return urldecode(json_encode(url_encode($str)));
}
/**
*
*/
function url_encode($str) {
if(is_array($str)) {
foreach($str as $key=>$value) {
unset($str[$key]);
$str[urlencode($key)] = url_encode($value);
}
} else {
$str = urlencode($str);
}
return $str;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment