PHP fgetcsv()似乎无法读取CSV文件中任何行的最后一个字段
I've used fgetcsv()
function to read data from a CSV file and import its information to MySQL. The data I have is something like this:
2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1
0,1,2,7,7,7,7,7,7,7,1,7,7,7,7,7,7
As you can see, each row has 17 fields and I must read them using their indexes from 0 to 17. But whenever I want to do it, I get an error that tells me there is not any index #17.
What is ther matter with it? I have to add a comma after the last field in each row ? If you answer is yes, why excel does not do it ? And how can I add a new ,
after each line of a CSV file ?
我使用 如您所见,每行有17个字段,我必须使用0到17之间的索引读取它们。但是每当我想要这样做时,我都会收到一个错误,告诉我没有任何索引 #17。 fgetcsv() code>函数从CSV文件中读取数据并导入 它的信息到MySQL。 我的数据是这样的: p>
2,3,4,5,6,7,8,9,9,8,7,6,5,4 ,3,2,1
0,1,2,7,7,7,7,7,7,7,1,7,7,7,7,7,7
代码> PRE>
它有什么用呢? 我必须在每行的最后一个字段后添加一个逗号? 如果您回答是,为什么excel不这样做? 如何在CSV文件的每一行之后添加新的, code>? p>
div>
There are only 17 columns (as you seem to have counted yourself), so you get indices from 0
(first column) to 16
(17th column).