Home  >  Article  >  php教程  >  son_encode alternative function php_json_encode

son_encode alternative function php_json_encode

高洛峰
高洛峰Original
2016-11-28 16:48:221385browse

Since the json_encode function requires php5.20 or above to be supported, how can we use the json function if php does not support json_encode? Is there any alternative function? There is no alternative function, but someone has made a custom php_json_encode. It is not known what problems will occur during use.

[php]
function php_json_encode($arr)
{
 $ json_str = "";
if(is_array($arr))
{
$pure_array = true;
$array_length = count($arr);
for($i=0;$i<$array_length;$i++)
{
                                                                                                                         {
                                                                                                                             array();
for($i=0;$i<$array_length;$i++)
{
$temp[] = sprintf("%s", php_json_encode($arr[$i]));
}
$json_str .= implode(",",$temp);
                  $json_str                                                                                                                  foreach($arr as $ key = & gt; $ value) {
$ Temp [] = sprintf (""%s ":%s", $ key, php_json_encode ($ value));
}
$ json_Str. ",$temp);
$json_str .="}";
}
}
else
{
if(is_string($arr))
{
$json_str = """. $arr) . "" ";
                                                                                                                                                                                                                                 _string($arr) . """;
}
}
  return $json_str;
}

function json_encode_string($in_str) {
  mb_internal_encoding("UTF-8");
  $convmap = array(0x80, 0xFFFF, 0, 0xFFFF);
  $str = "";
for ($i = mb_strlen($in_str)-1; $i>=0; $i--) {
            $mb_char = mb_substr($in_str, $i, 1);
                                                                                             ;
              $str = $mb_char .

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn