I've got a csv file being delivered via ftp twice a day. I'm trying to write a php file to open this file, filter it by the category column, delete rows which don't have a certain term/terms in then save the file.
I've tried lots of variants of snippets of code found on the internet but can't for the life of me figure out how to get it to work.
I tried using a variant of the code found in this question but couldn't make it work in my scenario
Filter a csv file by a word or text using php
If it helps the csv file I am trying to edit is located here: http://accurateav.co.uk/sahara/saharafeed.csv
<?php
$file = fopen('saharafeed.csv', 'r');
// You can use an array to store your search words, makes things more flexible.
// Supports any number of search words.
$words = array('casio');
// Make the search words safe to use in regex (escapes special characters)
$words = array_map('preg_quote', $words);
$regex = '/'.implode('|', $words).'/i';
while (($line = fgetcsv($file)) !== FALSE) {
list($ExportDate, $ItemCode, $Manufacturer, $Model, $ProductName, $DealerPrice, $Stock, $RRP, $Category, $ShortDesc, $LongDesc, $Weightkg, $EAN, $NonStock, $LargePictureURL, $SpecSheet, $HiResPhoto1, $HiResPhoto2) = $line;
if(preg_match($regex, $Category)) {
echo "$ExportDate, $ItemCode, $Manufacturer, $Model, $ProductName, $DealerPrice, $Stock, $RRP, $Category, $ShortDesc, $LongDesc, $Weightkg, $EAN, $NonStock, $LargePictureURL, $SpecSheet, $HiResPhoto1, $HiResPhoto2<br />\n";
}
}
?>
This is the code I have used so far to filter the category to only show products in the Casio category however when i run the script no results are shown even though there are numerous products under the casio category.