I use PHP to import data from a CSV file using fgetcsv (), which gives an array for each row. Initially, I had a character limit set to 1024, for example:
while ($data = fgetcsv($fp, 1024)) {
However, a CSV with 200+ columns exceeded the limit of 1024 in many rows. This caused the line to be stopped in the middle of the line, and then the next call to fgetcsv () will begin where the previous one stopped, and so on, until EOL is reached.
Since then, I have increased this limit to 4096, which should take care of most cases, but I would like to put a check to make sure that the entire line has been read after each line. How can I do it?
I was thinking of checking the end of the last element of the array for line-term characters (\ n, \ r, \ r \ n), but wouldn't they be handled by fgetcsv ()?
source share