note 93860 added to function.json-encode

From: Date: Sun, 04 Oct 2009 07:13:36 +0000
Subject: note 93860 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-161257@lists.php.net to get a copy of this message
<?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; } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 74.63.93.161 ---- Manual Page -- http://www.php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/93860 Del: integrated -- https://master.php.net/note/delete/93860/integrated Del: useless -- https://master.php.net/note/delete/93860/useless Del: bad code -- https://master.php.net/note/delete/93860/bad+code Del: spam -- https://master.php.net/note/delete/93860/spam Del: non-english -- https://master.php.net/note/delete/93860/non-english Del: in docs -- https://master.php.net/note/delete/93860/in+docs Del: other reasons-- https://master.php.net/note/delete/93860 Reject -- https://master.php.net/note/reject/93860 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161257) next »