Possible Duplicate:
how to extract data from csv file in php
I need to do it for a huge CSV file with help of PHP.
Possible Duplicate:
how to extract data from csv file in php
I need to do it for a huge CSV file with help of PHP.
Use fgetcsv
function. It gets a line from file pointer and parse for CSV fields.
Following example reads a CSV file myfile.csv
, gets the records and displays them line by line.
<?php
$row = 1;
//open the file
if (($handle = fopen("myfile.csv", "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 0, ",")) !== FALSE)
{
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
?>