note 64396 added to function.print-r

From: Date: Thu, 13 Apr 2006 14:01:05 +0000
Subject: note 64396 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-107986@lists.php.net to get a copy of this message
Bases on thbley´s sript i use this one to log some actions. It will return a tabbed like string which you can output or whatever. Input fields like "Password" will not be shown. <?php function print_r_string($arr,$first=true,$tab=0) { $output = ""; $tabsign = ($tab) ? str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$tab) : ''; if ($first) $output .= "<pre><br>\n"; foreach($arr as $key => $val) { switch (gettype($val)) { case "array": $output .= $tabsign."[".htmlspecialchars($key)."] = array(".count($val).")<br>\n".$tabsign."(<br>\n"; $tab++; $output .= print_r_string($val,false,$tab); $tab--; $output .= $tabsign.")<br>\n"; break; case "boolean": $output .= $tabsign."[".htmlspecialchars($key)."] bool = '".($val?"true":"false")."'<br>\n"; break; case "integer": $output .= $tabsign."[".htmlspecialchars($key)."] int = '".htmlspecialchars($val)."'<br>\n"; break; case "double": $output .= $tabsign."[".htmlspecialchars($key)."] double = '".htmlspecialchars($val)."'<br>\n"; break; case "string": $output .= $tabsign."[".htmlspecialchars($key)."] string = '".((stristr($key,'passw')) ? str_repeat('*', strlen($val)) : htmlspecialchars($val))."'<br>\n"; break; default: $output .= $tabsign."[".htmlspecialchars($key)."] unknown = '".htmlspecialchars(gettype($val))."'<br>\n"; break; } } if ($first) $output .= "</pre><br>\n"; return $output; } echo print_r_string(array($_POST,$_GET)); // for Example ?> ---- Server IP: 217.13.201.10 Probable Submitter: 213.128.118.127 ---- X-Spam-Status: Yes, hits=7.6 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HEAD_ILLEGAL_CHARS,HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.print-r.php Edit -- http://master.php.net/note/edit/64396 Del: integrated -- http://master.php.net/note/delete/64396/integrated Del: useless -- http://master.php.net/note/delete/64396/useless Del: bad code -- http://master.php.net/note/delete/64396/bad+code Del: spam -- http://master.php.net/note/delete/64396/spam Del: non-english -- http://master.php.net/note/delete/64396/non-english Del: in docs -- http://master.php.net/note/delete/64396/in+docs Del: other reasons-- http://master.php.net/note/delete/64396 Reject -- http://master.php.net/note/reject/64396 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107986) next »