Example code for reading csv file contents with PHP_PHP tutorial

WBOY
Release: 2016-07-20 11:15:30
Original
761 people have browsed it

Read the data of all rows in the csv file at one time
}
} */
echo $goods_list[2][0];
fclose($file);
?>

Read a certain row of data from the csv file

Read the csv file and specify the number of lines (line interval)
}
?>

Two other methods found online (haven’t tested it, so I don’t know if it works)

$handle=fopen("1.csv","r");
while(!feof($handle)){
$buffer=fgetss($handle,2048);
$ data=explode(",",$buffer);
$num=count($data);
for($i=0;$i<$num;$i++){
print_r($ data);
}
}
?>>

Code 2,

$handle=fopen("1.csv","r");
$row=1;
while($data=fgetcsv($handle,1000,", ")){
$num=count($data);
for($i=0;$i<$num;$i++){
echo $data[$i];
}
$row++;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440198.htmlTechArticleRead the data of all rows in the csv file at once $file = fopen('windows_2011_s.csv','r '); while ($data = fgetcsv($file)) { //Read one line of content in CSV each time //print_r($data); //This...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!