Here is the script I have:
$host = "http://www.test.com/feed.csv";
$rowcount = 0;
$error = '';
$flag = 0;
$fp = fopen($host,"r") or die("can't open file");
while($csv_line = fgetcsv($fp,'1084')) {
$do = array($csv_line);
// check structure of .csv file for matching layout
if ($rowcount == 0){
if (($do[0][0] == "ID") &&
($do[0][1] == "SKU") &&
($do[0][2] == "PRICE") &&
($do[0][3] == "SALE-PRICE") &&
($do[0][4] == "STOCK") &&
($do[0][5] == "WEIGHT") &&
($do[0][6] == "CATEGORIES") &&
($do[0][7] == "COLOR-:-SIZE~QTY") &&
($do[0][8] == "DESCRIPTION") &&
($do[0][9] == "THUMBNAIL") &&
($do[0][10] == "LARGE-IMAGE")){
echo ".CSV STRUCTURE - PASSED...<br>";
echo "---------------------------------<br>";
} else {
// email admin script error
echo "Bad match!";
die();
}
}
#$numfields = count($csv_line);
#for($i=0; $i<$numfields; $i++)
# {
# echo $i.":".$csv_line[$i]."<br>";
# }
if ($rowcount > 0){
$Productid=$csv_line[0];
$Productsku=$csv_line[1];
$Productprice=$csv_line[2];
$Productsaleprice=$csv_line[3];
$Productstock=$csv_line[4];
$Productweight=$csv_line[5];
$Productcategory=$csv_line[6];
$Productcolor=$csv_line[7];
$Productdescription=$csv_line[8];
$Productthumb=$csv_line[9];
$Productlimage=$csv_line[10];
// insert into database or edit variable here
$Productdescription = str_replace($Productsku." -", "", $Productdescription);
$regexp = '#(?<=^|;)(\b.*\b)\s*-:-\s*(\b.*\b)\s*~\s*(\b.*\b)(?=;|$)#U';
preg_match_all($regexp, $Productcolor, $matches, PREG_SET_ORDER);
echo "<pre>".print_r($matches, 1)."</pre>";
$colors = count($matches);
echo "Results: ".$colors;
for($i=0; $i<$colors; $i++){
echo $i.":".$matches[$i][1]."<br>"; // HELP HERE TO GET INDIVIDUAL ITEMS FOR DATABASE INSERT
}
echo $Productid." ".$Productdescription." ".$matches[1]."<br>";
}
$rowcount++;
}
fclose($fp) or die("can't close file");
I need help now getting each individual array then to insert into the database. Please help once more. I marked where i need help in the script with (// help here)