note 101532 deleted from function.print-r by danbrown
| From: | danbrown@php.net | Date: | Wed, 22 Dec 2010 23:27:19 +0000 |
| Subject: | note 101532 deleted from function.print-r by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175152@lists.php.net to get a copy of this message | ||
Note Submitter: Andrew
----
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;
}
}