How can we validate a CSV file ?
I have an CSV file of structure:
Date;Id;Shown
15-Mar-10;231;345
15-Mar-10;232;346
and so on and on !!! approx around 80,000 rows.
How can I validate this CSV file before starting the parsing using fgetcsv ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would not try to validate the file before hand : I would rather prefer going through it line by line, dealing with each line separately :
Now, what could “verify it’s OK” means ?
fgetcsv, maybe some other function specific to my project — anyway, if I cannot read one line with my function that reads hundreds, it’s probably because there’s a problem on that line)If all that goes OK — well, not much more to do, excepts use the data 😉
And when you’re done with one line, just go repeat for the next one.
Of course, if you want to either accept or reject a whole file before doing any database *(or anything like that)* write, you’ll have to :
In your specific case, you have three kind of fields :
From what I can guess :
strtotime(not sure it’s ok for the format you’re using, though)explodethe stringJan,Feb,Mar, …