PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm trying to parse a csv file via php. The code below worked except for a warning about an invalid argument in the foreach() statement. I tried a couple of things to rectify the problem and none worked. I have completely removed all the changes (double and triple checked) and now I only get the warning and no data. Any ideas what the problem may be? It seems that $row is not accepted as an array, but the fgetcsv() function should return an array to it. I've tried to implicitly assign $row as an array and then push the csv into it, but then there is no data or warning.
Not every row necessarily contains CSV data (there could be empty rows to separate batches of data). You should put a check regardless on whether fgetcsv returns false or not.
Ok, I've put a check in code as follows, which gets rid of the warning but displays "Error". $row, therefore is not an array, I get that. But it should keep running the fgetcsv til the eof is reached. Therefore, unless the file is empty (which it isn't) then the remining rows in the file should be displayed. Or am I completly missing something?
Did you check that any of the rows are actually array? is it possible the delimiter is different from the default (a comma) - maybe a space or a semi-colon?