Last active
August 29, 2015 14:19
-
-
Save branchzero/eb908ff4341a4741e7fe to your computer and use it in GitHub Desktop.
Array To Json (Any Charset Auto-Convert To UTF-8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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