I have data in a CSV file. I need to read the file and put the data into an array. I have 5 columns in my CSV file, like this:
CAPRICCIOSA | Tomato, Cheese, Mushrooms | $8.00 | $12.00 | $15.00
MARGHERITA | Tomato, Cheese, Oregano | $7.00 | $11.00 | $13.00
-
How can I
explode()it into array? If I use a comma to explode it into array, it will becomeCAPRICCIOA - Tomato - Cheesebecause my text already has a comma. -
How can I split it into different rows, like MySQL so I can loop through the results?
I have tried the following:
$file="dish.csv" ;
$file=file_get_contents($file);
$array=explode(",", $file);
How about using PHP function : fgetcsv()
http://php.net/manual/en/function.fgetcsv.php