JSON indentation in PHP
This question already has an answer here:
From PHP 5.4 onwards, json_encode has a JSON_PRETTY_PRINT flag
$pretty=json_encode($foo, JSON_PRETTY_PRINT);
If you're stuck with an ancient version of PHP, then the manual page for json_encode includes a user-contributed sample showing how to pretty-print JSON.
In fact, json_encode
has an option to do pretty-print in PHP 5.4 . To use it:
<pre>
<?php echo nl2br(json_encode($yourArrayOrObject, JSON_PRETTY_PRINT)); ?>
</pre>
链接地址: http://www.djcxy.com/p/47268.html
上一篇: 格式化echo json
下一篇: PHP中的JSON缩进