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 开发者_StackOverflow中文版am interested in removing all columns in the .csv which I don't recognize. How can php do this?
(The names of the columns are defined in the first row of the file.)
In PHP use fgetcsv() to read in your CSV file, ignore the columns you want and then write back to a CSV file using fputcsv();
Look at fgetcsv and fputcsv. Read the contents, write the columns/data back out that you want.
精彩评论