note 92539 added to function.json-encode

From: Date: Tue, 28 Jul 2009 19:41:50 +0000
Subject: note 92539 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-158838@lists.php.net to get a copy of this message
I wrote a function to make JSON strings more readable. It's very useful for debugging JSON output... function jsonReadable($json, $html=FALSE) { $tabcount = 0; $result = ''; $inquote = false; $ignorenext = false; if ($html) { $tab = "&nbsp;&nbsp;&nbsp;"; $newline = "<br/>"; } else { $tab = "\t"; $newline = "\n"; } for($i = 0; $i < strlen($json); $i++) { $char = $json[$i]; if ($ignorenext) { $result .= $char; $ignorenext = false; } else { switch($char) { case '{': $tabcount++; $result .= $char . $newline . str_repeat($tab, $tabcount); break; case '}': $tabcount--; $result = trim($result) . $newline . str_repeat($tab, $tabcount) . $char; break; case ',': $result .= $char . $newline . str_repeat($tab, $tabcount); break; case '"': $inquote = !$inquote; $result .= $char; break; case '\\': if ($inquote) $ignorenext = true; $result .= $char; break; default: $result .= $char; } } } return $result; } ---- Server IP: 69.147.83.197 Probable Submitter: 99.24.61.158 ---- Manual Page -- http://www.php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/92539 Del: integrated -- https://master.php.net/note/delete/92539/integrated Del: useless -- https://master.php.net/note/delete/92539/useless Del: bad code -- https://master.php.net/note/delete/92539/bad+code Del: spam -- https://master.php.net/note/delete/92539/spam Del: non-english -- https://master.php.net/note/delete/92539/non-english Del: in docs -- https://master.php.net/note/delete/92539/in+docs Del: other reasons-- https://master.php.net/note/delete/92539 Reject -- https://master.php.net/note/reject/92539 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158838) next »