note 118569 added to function.json-encode
| From: | rdeeceria | Date: | Wed, 30 Dec 2015 03:38:45 +0000 |
| Subject: | note 118569 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204565@lists.php.net to get a copy of this message | ||
reading json pretty of my code. i have simple code for easy read array, object, path, etc
json pretty print with str_replace ( \r \n \t ) and preg_replace ( \ ).
function jsonDump ($a,$die = true)
{
$json = str_replace(array("\\r","\\n","\\t"),
"",json_encode($a,JSON_PRETTY_PRINT));
$json = preg_replace('#(?<!\\\\)(\\$|\\\\)#', "", $json);
echo'<pre>';
print_r($json);
echo'</pre><hr>';
if($die) die();
}
//input
$infoPath = array (
'method' => $_SERVER['REQUEST_METHOD'],
'status' => $status,
'dirbatch' => $dirbatch,
'pathData' => $path_data //array
);
//output
{
"method": "GET",
"status": "ins_tarif",
"dirbatch": "C:\xampp\htdocs\simrs\services",
"pathData": [
"E:\Brankas\Project\RSIA\SIMRS\dump\DOKTER.csv",
"E:\Brankas\Project\RSIA\SIMRS\dump\GOLPAS.csv",
"E:\Brankas\Project\RSIA\SIMRS\dump\PANGKAT.csv",
"E:\Brankas\Project\RSIA\SIMRS\dump\PEMAKAI.csv"
]
}
Hope it works well for you :)
----
Server IP: 72.52.91.14
Probable Submitter: 180.252.117.208
----
Manual Page -- http://php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/118569
Del: integrated -- https://master.php.net/note/delete/118569/integrated
Del: useless -- https://master.php.net/note/delete/118569/useless
Del: bad code -- https://master.php.net/note/delete/118569/bad+code
Del: spam -- https://master.php.net/note/delete/118569/spam
Del: non-english -- https://master.php.net/note/delete/118569/non-english
Del: in docs -- https://master.php.net/note/delete/118569/in+docs
Del: other reasons-- https://master.php.net/note/delete/118569
Reject -- https://master.php.net/note/reject/118569
Search -- https://master.php.net/manage/user-notes.php