note 100738 deleted from function.json-decode by nicobn
| From: | nicobn@php.net | Date: | Wed, 03 Nov 2010 21:50:25 +0000 |
| Subject: | note 100738 deleted from function.json-decode by nicobn | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173729@lists.php.net to get a copy of this message | ||
Note Submitter: jamespam at hotmail dot com
Reason: 1
----
decode json (with array data) to php array PHP<5
<?php
if ( !function_exists('json_decode') ){
function json_decode($json)
{
$comment = false;
$out = '$x=';
for ($i=0; $i<strlen($json); $i++)
{
if (!$comment)
{
if (($json[$i] == '{') || ($json[$i] == '[')) $out .= '
array(';
else if (($json[$i] == '}') || ($json[$i] == ']')) $out .=
')';
else if ($json[$i] == ':') $out .= '=>';
else $out .= $json[$i];
}
else $out .= $json[$i];
if ($json[$i] == '"') $comment = !$comment;
}
debug($out);
eval($out . ';');
return $x;
}
}
?>