LOAD_DATAFEED

CSV Deserializer and Datafeed Loader.

[[LOAD_DATAFEED:filename|delimiter]]

A datafeed is any csv or tab delimited text file with 3 or more fields per line. Other delimiters may also be used.

filename (string) may either be php$ variable or string value.

delimiter(string) is the separator between the fields in each row.

Example: the data file csv_datafeed.txt contains:

name,id,color,size
Washington,1,blue,big
Oregon,2,"green",small
California,3,red,huge

The following code will import the datafeed or csv file and deserialize it into variable memory. Field names are populated to the matrix_fields array. Arrays with names corresponding to column field names will be populated with the row values.

[[LOAD_DATAFEED:csv_datafeed.txt|,]]

Use php to test dump the variables:

<?php
print_r($matrix_fields);
print_r($name);
print_r($id);
print_r($color);
print_r($size);
?>

Note that since the pipe symbol is a reserved delimiter in the TerraDctl shortcodes, it should not be used inside a shortcode for anything other than separating  parameters.  For pipe delimited files:

<?php $pipe="|"; ?>
[[LOAD_DATAFEED:csv_datafeed.txt|$pipe]]
 

Leave a Reply