CSV Spreadsheet and Datafeed Loader.
[[CSV_DESERIALIZE:filename|delimiter]]
A datafeed is any character 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. Note that the csv parser must be loaded before using.
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,colors,size Washington,1,blue,big Oregon,2,"yellow,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 created and populated with the row values. Note that the csv parser function must be loaded first by the cablebox front controller.
[[CABLEBOX:csv_parser]] [[READ_FILE:csv_datafeed.txt|csv_data]] [[CSV_DESERIALIZE:csv_data|,]]
Example assumes that the matrix fields(column headers) from the csv file are name, id,colors and size. Use php print_r to test dump the variables:
[[:print_r($matrix_fields);]] [[:print_r($name);]] [[:print_r($id);]] [[:print_r($colors);]] [[: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:
[[:$pipe="|";]] [[CSV_DESERIALIZE:csv_datafeed.txt|$pipe]]
The csv parser loaded by the front controller includes the TerraDctl php extension parse_csv().
direct usage:
[[CABLEBOX:csv_parser]] [[READ_FILE:csv_datafeed.txt|csv_data]] [[:$csv_array=parse_csv($csv_data);]] [[:print_r($csv_array);]]
Nests all the row and column values into 2 dimensional indexed arrays.