|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-11-08 08:01 UTC] Otto dot Stolz at uni-konstanz dot de
print_r writes directly to php://output, hence its output should comply with HTML syntax rules. However, print_r will issue non-compliant code, or generate spurious entities, whenever a variable contains an HTML special character. Hence, print_r should apply htmlspecialchars to all strings it is going to write to php://output. Try the demo at <http://www.rz.uni-konstanz.de/Antivirus/tests/print_r.php> with Netscape 6, or Opera 6, as IE 6 will not reveal all the surprises I've hidden therein ;-) The pertinent PHP source can be seen at <http://www.rz.uni-konstanz.de/Antivirus/tests/print_r.txt>. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 16:00:01 2025 UTC |
Look - it's really simple: <?php function ob_smart_html_handler($string) { $string = (isset($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($string) : $string; return $string; } // create $var here ob_start('ob_smart_html_handler'); print_r($var); ob_end_flush(); ?> Additionally, using 4.3.0 (slightly different output): <?php print(htmlspecialchars(var_export($var, TRUE))); ?> Now - those few lines of 'extra' code, simply don't warrant a change in behavior, that has the potential to break CLI code.