note 38481 added to function.var-export
| From: | (alonsoatmkdotcomdotbr) | Date: | Tue, 23 Dec 2003 17:38:52 +0000 |
| Subject: | note 38481 added to function.var-export | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62381@lists.php.net to get a copy of this message | ||
Here is a better version for PHP that not have support to var_export (less than 4.2.0).
It's a little modification of the function posted below, but with a good result.
Enjoy it.
- Alonso Andres
<?php
if (!function_exists("var_export")) {
function var_export() {
$arg = func_get_args();
$array = $arg[0];
$return = $arg[1];
if (isset($arg[2]))
$tabs = $arg[2];
else
$tabs = "";
if (is_array($array)) {
$out = "array (\n";
foreach($array as $k => $v) {
if (is_numeric($k)) {
$out .= $tabs . "\t$k => ";
} else {
$out .= $tabs . "\t'$k' => ";
}
if (is_array($v) && $k != "GLOBALS"){
$out .= var_export($v, true, $tabs . "\t");
} elseif ($k !== "GLOBALS") {
if (gettype($v) != "string" && !empty($v)) {
$out .= $v . ",\n";
} else {
$out .= "'$v'" . ",\n";
}
} else {
$out .= "GLOBALS: not allowed!\n";
}
}
if ($tabs != "")
$out .= $tabs . ");" . "\n";
else
$out .= ");" . "\n";
} else {
$out = $array;
}
if ($return == true) {
return $out;
} else {
echo $out;
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.var-export.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38481
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38481&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38481&report=yes
Search -- http://master.php.net/manage/user-notes.php