function export_node_encode in Node export 5.2
Same name and namespace in other branches
- 6 export.pages.inc \export_node_encode()
build node code string recursively
1 call to export_node_encode()
- export_node_export in ./
export.pages.inc - Exports a node - return export code in a textarea
File
- ./
export.pages.inc, line 304
Code
function export_node_encode($var, $iteration = 0) {
$tab = '';
for ($i = 0; $i < $iteration; $i++) {
$tab = $tab . " ";
}
$iteration++;
if (is_object($var)) {
$var = (array) $var;
$var['#_export_node_encode_object'] = '1';
}
if (is_array($var)) {
$empty = empty($var);
$code = "array(" . ($empty ? '' : "\n");
foreach ($var as $key => $value) {
$code .= $tab . " '" . $key . "' => " . export_node_encode($value, $iteration) . ",\n";
}
$code .= ($empty ? '' : $tab) . ")";
return $code;
}
else {
if (is_string($var)) {
// Escape single quotes so we don't accidentally exit the string.
return "'" . strtr($var, array(
"'" => "\\'",
)) . "'";
}
elseif (is_numeric($var)) {
return $var;
}
elseif (is_bool($var)) {
return $var ? 'TRUE' : 'FALSE';
}
else {
return 'NULL';
}
}
}