New function: sm_print_r()
authortassium <tassium@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 3 Jul 2003 14:14:48 +0000 (14:14 +0000)
committertassium <tassium@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 3 Jul 2003 14:14:48 +0000 (14:14 +0000)
This is intended to be a debugging function.  Ever wanted to do a print_r, but found that some of the values were "eaten" by your browser's parser because they had <> in them?  Use this function instead.  It runs htmlentities() on the output of print_r() AND as a bonus wraps the entire thing in <pre> and </pre> tags.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@5199 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/strings.php

index c9e583f623b848ac73191b9bc139d43e9ba19e41..ee4fa5965a53316537ec4db4a75824337d442531 100644 (file)
@@ -438,6 +438,23 @@ function makeComposeLink($url, $text = null)
     return makeInternalLink($url, $text, '_blank');
 }
 
+/** 
+* sm_print_r($some_variable);
+* Debugging function - does the same as print_r, but makes sure special
+* characters are converted to htmlentities first.  This will allow
+* values like <some@email.address> to be displayed.
+* The output is wrapped in <pre> and </pre> tags.
+*/
+function sm_print_r($var) {
+    ob_start();  // Buffer output
+    print_r($var);
+    $buffer = ob_get_contents(); // Grab the print_r output
+    ob_end_clean();  // Silently discard the output & stop buffering
+    print "<pre>";
+    print htmlentities($buffer);
+    print "</pre>";
+}
+
 $PHP_SELF = php_self();
 
 ?>