function node_export_dsv_decode in Node export 7.3
Same name and namespace in other branches
- 6.3 modules/node_export_dsv/node_export_dsv.module \node_export_dsv_decode()
Interpret a DSV string.
1 call to node_export_dsv_decode()
- node_export_dsv_import in formats/
dsv.inc - Import callback.
File
- formats/
dsv.inc, line 209 - The Node export DSV format handler.
Code
function node_export_dsv_decode($code_string, $delimiter, $enclosure, $separator) {
// Get array data from DSV.
$array = @node_export_dsv_dsv_to_array($code_string, $delimiter, $enclosure, $separator);
// If the first two rows are of equal length, we can assume this is a DSV.
// Also checks there are a decent number of fields.
if (!empty($array[0]) && !empty($array[1]) && count($array[0]) > 10 && count($array[0]) == count($array[1])) {
$nodes = array();
// Assume row 0 is the header, and the rest of the rows are the nodes.
$header = array_shift($array);
// Build the nodes.
foreach ($array as &$row) {
$node = (object) array();
foreach ($row as $key => $item) {
$item = node_export_dsv_decode_sanitize_value($item);
eval('$node->' . $header[$key] . ' = ' . $item . ';');
}
$nodes[] = $node;
}
return $nodes;
}
}