这是我正在使用的代码,但它并没有准确输出我想要的内容。<?php$file = fopen("ad.csv","r");while(! feof($file)) { print_r(fgetcsv($file)); }fclose($file);?>这是它当前输出的内容:Array ( [0] => cn [1] => mail [2] => telephonenumber [3] => uid ) Array ( [0] => [1] => [2] => [3] => ) Array ( [0] => admin [1] => [2] => [3] => ) Array ( [0] => Isaac Newton [1] => newton@ldap.forumsys.com [2] => [3] => newton ) Array ( [0] => Albert Einstein [1] => einstein@ldap.forumsys.com [2] => 314-159-2653 [3] => einstein ) Array ( [0] => Nikola Tesla [1] => tesla@ldap.forumsys.com [2] => [3] => tesla ) Array ( [0] => Galileo Galilei [1] => galieleo@ldap.forumsys.com [2] => [3] => galieleo ) Array ( [0] => Leonhard Euler [1] => euler@ldap.forumsys.com [2] => [3] => euler ) Array ( [0] => Carl Friedrich Gauss [1] => gauss@ldap.forumsys.com [2] => [3] => gauss ) Array ( [0] => Bernhard Riemann [1] => riemann@ldap.forumsys.com [2] => [3] => riemann ) Array ( [0] => Euclid [1] => euclid@ldap.forumsys.com [2] => [3] => euclid ) Array ( [0] => Mathematicians [1] => [2] => [3] => ) Array ( [0] => Scientists [1] => [2] => [3] => ) Array ( [0] => read-only-admin [1] => [2] => [3] => ) Array ( [0] => Italians [1] => [2] => [3] => ) Array ( [0] => Test [1] => [2] => [3] => test ) Array ( [0] => Chemists [1] => [2] => [3] => ) Array ( [0] => Marie Curie [1] => curie@ldap.forumsys.com [2] => [3] => curie ) Array ( [0] => Alfred Nobel [1] => nobel@ldap.forumsys.com [2] => [3] => nobel ) Array ( [0] => Robert Boyle [1] => boyle@ldap.forumsys.com [2] => 999-867-5309 [3] => boyle ) Array ( [0] => Louis Pasteur [1] => pasteur@ldap.forumsys.com [2] => 602-214-4978 [3] => pasteur ) Array ( [0] => No Group [1] => nogroup@ldap.forumsys.com [2] => [3] => nogroup ) Array ( [0] => FS Training [1] => training@forumsys.com [2] => 888-111-2222 [3] => training ) Array ( [0] => FS Training [1] => jmacy-training@forumsys.com [2] => 888-111-2222 [3] => jmacy )换句话说,这几乎就像将我所有的 CSV 数据添加到一个多维数组中一样......
1 回答
函数式编程
TA贡献1807条经验 获得超9个赞
顺便说一句,在 php 7.2 中这也可以工作:
<?php
$row = 1;
if (($handle = fopen("ad.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo ($data[0].",".$data[1].",".$data[2].",".$data[3]."\n");
}
fclose($handle);
}
?>
此外,.csv 数据上的引号应包含所有数据,例如:
"Isaac Newton","newton@ldap.forumsys.com",,"newton"
"Albert Einstein","einstein@ldap.forumsys.com","314-159-2653","einstein"
"Nikola Tesla","tesla@ldap.forumsys.com",,"tesla"
"Galileo Galilei","galieleo@ldap.forumsys.com",,"galieleo"
- 1 回答
- 0 关注
- 132 浏览
添加回答
举报
0/150
提交
取消