chouaib23 chouaib23 - 6 months ago 95
PHP Question

PHP read CSV file line by lines

i have csv from http link

and i want foreach row line by line in PHP code

my csv code is :

1004000018;active;"TEST1";"TEST2";"TEST3";"TEST4"

i want get

1004000018
active
TEST1
TEST2
TEST3
TEST4

row by row

thanks

Answer

You can achieve this using the php function fgetcsv, this should work :

PHP

$file = fopen('file.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
   //$line[0] = '1004000018' in first iteration
   print_r($line);
}

fclose($file);