note 101532 added to function.print-r
| From: | Andrew at osu1 dot php dot net | Date: | Wed, 22 Dec 2010 23:26:04 +0000 |
| Subject: | note 101532 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175150@lists.php.net to get a copy of this message | ||
I wrote this function as I had arrays containing HTML, which was being output to the page without
being run through htmlentities.
It could probably do with a few tweaks, but it works for my needs. Note the $input param accepts
arrays only with the function in its current state:
function print_r_htmlentities($input, $output = false){
$return = "";
if(is_array($input)){
foreach($input as $key => $value){
if(is_array($value)){
$return .= "[" . htmlentities($key) . "] => Array(" .
print_r_htmlentities($value, true) . ")\r\n";
} elseif(is_object($value)){
$return .= "[" . htmlentities($key) . "] => " . get_class($value)
. " Object (" . print_r_htmlentities(get_object_vars($value), true) . ")\r\n";
} elseif(is_string($value) || is_numeric($value)){
$return .= "[" . htmlentities($key) . "] => " .
htmlentities($value) . "\r\n";
} elseif(is_null($value)){
$return .= "[" . htmlentities($key) . "] => NULL\r\n";
} elseif(is_bool($value)){
$return .= "[" . htmlentities($key) . "] => " . ($value === true
? "TRUE" : "FALSE") . "\r\n";
} elseif(is_resource($value)){
$return .= "[" . htmlentities($key) . "] => Resource type: " .
get_resource_type($value) . "\r\n";
} else {
$return .= "[" . htmlentities($key) . "] is" . gettype($value) .
"\r\n";
}
}
} else {
$return .= "[" . htmlentities($key) . "] is" . gettype($value) .
"\r\n";
}
if($output == true){
return $return;
} else {
echo $return;
return;
}
}
----
Server IP: 117.104.162.229
Probable Submitter: 203.45.56.190 (proxied: 203.45.56.190)
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- https://master.php.net/note/edit/101532
Del: integrated -- https://master.php.net/note/delete/101532/integrated
Del: useless -- https://master.php.net/note/delete/101532/useless
Del: bad code -- https://master.php.net/note/delete/101532/bad+code
Del: spam -- https://master.php.net/note/delete/101532/spam
Del: non-english -- https://master.php.net/note/delete/101532/non-english
Del: in docs -- https://master.php.net/note/delete/101532/in+docs
Del: other reasons-- https://master.php.net/note/delete/101532
Reject -- https://master.php.net/note/reject/101532
Search -- https://master.php.net/manage/user-notes.php