Req #48154 [Opn]: Add optional paramter to print_r() for basic (X)HTML output formatting

From: Date: Sat, 02 May 2015 12:03:29 +0000
Subject: Req #48154 [Opn]: Add optional paramter to print_r() for basic (X)HTML output formatting
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192457@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48154&edit=1 ID: 48154 Updated by: cmb@php.net Reported by: stepheneliotdewey at gmail dot com Summary: Add optional paramter to print_r() for basic (X)HTML output formatting Status: Open Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: irrelevant PHP Version: 5.2.9 Block user comment: N Private report: N New Comment: You could write an own function to format the output: function print_r_html($val) { echo '<pre>', htmlspecialchars(print_r($val, true)) , '</pre>'; } Another option would be to use var_dump(), which gives a nicely formatted and syntax highlighted output when Xdebug is installed. Previous Comments: ------------------------------------------------------------------------ [2009-05-05 17:18:34] stepheneliotdewey at gmail dot com Description: ------------ Output of print_r() is often viewed in a web browser, but in this setting, objects are rendered as long strings that are hard to read, because they have lots of properties, nested objects, etc. It is much easier to view such output by viewing page source (i.e. actual PHP output), since that will take into account newlines/whitespace characters that are ignored by (X)HTML browsers. However, it would be nice to have an optional parameter to make print_r() format its output for a browser (e.g. maybe <div>'s with inline CSS padding to force indentation, or at least <br /> and &nbsp;). Since print_r() is primarily a debugging tool, this could be pretty handy during development, and could encourage greater adoption of OOP practices. ALTERNATIVELY, a tip should be added to the print_r() documentation page telling users that arrays and objects printed by print_r() can be viewed more easily by looking directly at the source of the output, rather than through a browser. Reproduce code: --------------- N/A, see above. Expected result: ---------------- N/A, see above. Actual result: -------------- N/A, see above. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=48154&edit=1

« previous php.bugs (#192457) next »