1

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. How can php do this?

(The names of the columns are defined in the first row of the file.)

3
  • May I ask why? Whenever I parse CSV files, I simply ignore the columns I don't need. Commented Nov 9, 2010 at 15:52
  • @Pickle The script I have written is returning duplicate columns errors when I try to import it into a database, I suppose I am more interested in getting rid of columns that I don't recognize to avoid duplication. I suppose there can be another approach to this. Commented Nov 9, 2010 at 15:55
  • A similar question worth looking at: stackoverflow.com/questions/9814272/… Commented Jun 13, 2014 at 17:59

2 Answers 2

1

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();

Sign up to request clarification or add additional context in comments.

Comments

0

Look at fgetcsv and fputcsv. Read the contents, write the columns/data back out that you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.