php how to read csv file line by line

php-read-csv-line-by-line

ยท

1 min read

php how to read csv file line by line

Hi friend ๐Ÿ˜Ž

Do you know, how can you read csv file line by line in php ?

This is very common problem that PHP dev come across from time to time.

So below is code for reading csv file line by line in PHP. I hope this will help you.

You can achieve this using the php function fgetcsv

<?php
//filename is file.csv 
// if file placed in different directory you need to give full path of file 

$file = fopen('file.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
   print_r($line);
}
fclose($file);

?>
ย