LOAD_DATAFEED

Simple Datafeed Loader.

[[LOAD_DATAFEED:filename|delimiter]](deprecated)

Use [[CSV_DESERIALIZE]] instead.

A datafeed is any charactar delimited text file with 3 or more fields per line. Other delimiters may also be used. The first row must always contain the column header field names for it to be a proper datafeed. If you need to deserialize more complex comma seperated (csv) file data already loaded in variable memory or prepend the column headers/ field names into the first row then use [[CSV_DESERIALIZE]] instead.

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