function skinr_var_export in Skinr 7.2
Same name and namespace in other branches
- 8.2 skinr.module \skinr_var_export()
Export var function.
See also
1 call to skinr_var_export()
- skinr_object_export in ./
skinr.module - Export object function.
File
- ./
skinr.module, line 1041 - Handles core Skinr functionality.
Code
function skinr_var_export($var, $prefix = '', $init = TRUE) {
if (is_object($var)) {
$output = method_exists($var, 'export') ? $var
->export() : skinr_var_export((array) $var, '', FALSE);
}
else {
if (is_array($var)) {
if (empty($var)) {
$output = 'array()';
}
else {
$output = "array(\n";
foreach ($var as $key => $value) {
// Using normal var_export on the key to ensure correct quoting.
$output .= " " . var_export($key, TRUE) . " => " . skinr_var_export($value, ' ', FALSE) . ",\n";
}
$output .= ')';
}
}
else {
if (is_bool($var)) {
$output = $var ? 'TRUE' : 'FALSE';
}
else {
if (is_int($var)) {
$output = intval($var);
}
else {
if (is_numeric($var)) {
$output = floatval($var);
}
else {
if (is_string($var) && strpos($var, "\n") !== FALSE) {
// Replace line breaks in strings with a token for replacement
// at the very end. This protects whitespace in strings from
// unintentional indentation.
$var = str_replace("\n", "***BREAK***", $var);
$output = var_export($var, TRUE);
}
else {
$output = var_export($var, TRUE);
}
}
}
}
}
}
if ($prefix) {
$output = str_replace("\n", "\n{$prefix}", $output);
}
if ($init) {
$output = str_replace("***BREAK***", "\n", $output);
}
return $output;
}