Note Submitter: Sergey Aikinkulov
----
<?php
/*
Convert PHP array to JSON
--
Using:
- on server side: echo(arr2json([PHP array]))
- on client side(JavaScript): var obj = eval('(' + [XMLHTTPRequest.responseText] + ')');
*/
function arr2json($arr){
foreach($arr as $k=>&$val) $json[] = $k.':'.php2js($val);
if(count($json) > 0) return '{'.implode(',', $json).'}';
else return '';
}
function php2js($val){
if(is_array($val)) return arr2json($val);
if(is_string($val)) return '"'.addslashes($val).'"';
if(is_bool($val)) return 'Boolean('.(int) $val.')';
if(is_null($val)) return '""';
return $val;
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.