I'm fixing some PHP scripts and I'm missing ruby's pretty printer. i.e.
require 'pp' arr = {:one => 1} pp arr
will output {:one => 1}. This even works with fairly complex objects and makes digging into an unknown script much easier. Is there some way to duplicate this functionality in PHP?
PHP: print() function The print() function used to output one or more strings. The print() is not a real function, it is a language construct. Therefore there is no need to use parentheses with its argument list.
The docs say that these print to php://output . They are both language constructs, but at a guess, the difference is that print is an expression, but echo is a statement. printf and many friends.
The print keyword is used to output text. Unlike echo , print can only output one string at a time. Unlike echo , print has a return value, which is always 1.
Prettyprint can be done in many different ways. One of the basic implementations is code formatting, which splits blocks of code into individual code lines. Certain tools do this for various programming languages like LISP or C, making the result much more readable and conventional.
This is what I use to print my arrays:
<pre> <?php print_r($your_array); ?> </pre>
The magic comes with the pre
tag.
Both print_r()
and var_dump()
will output visual representations of objects within PHP.
$arr = array('one' => 1); print_r($arr); var_dump($arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With