简体   繁体   English

如何使用PHP从CSV文件中删除列?

[英]How to remove columns from a csv file with PHP?

I know the names of the columns I want to keep in the .csv file, but I am interested in removing all columns in the .csv which I don't recognize. 我知道我想保留在.csv文件中的列的名称,但是我有兴趣删除.csv中所有我不认识的列。 How can php do this? php如何做到这一点?

(The names of the columns are defined in the first row of the file.) (列名在文件的第一行中定义。)

在PHP中,使用fgetcsv()读取CSV文件,忽略所需的列,然后使用fputcsv()写回CSV文件。

Look at fgetcsv and fputcsv. 查看fgetcsv和fputcsv。 Read the contents, write the columns/data back out that you want. 阅读内容,写出所需的列/数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM