FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » fgetcsv -- No error reporting?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: fgetcsv -- No error reporting? [message #172811 is a reply to message #172810] Thu, 03 March 2011 17:09 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 03/03/2011 17:30, matt escribió/wrote:
> Hi all,
>
> Trying to process a fairly large csv file, and it's bombing out early on me. This quick test script describes the problem:
>
> # cat test.php
> <?php
>
> ini_set("display_errors", true);
> error_reporting(E_ALL | E_STRICT);
>
> $file = "my.csv";
> $fHandle = fopen($file, "r");
>
> $rowNum = 0;
> while (fgetcsv($fHandle)) ++$rowNum;
>
> printf ("Lines: %d\nLastRow: %d\n", count(file($file)), $rowNum);
>
> # php test.php
> Lines: 329360
> LastRow: 328141
>
>
> There are no multi-line entries in the file, so it seems to be legitimately returning false for some reason about 1200 lines early. A visual inspection of the file around line 328,141 doesn't reveal any errors, and no errors are being triggered from PHP/fgetcsv.
>
> Any ideas on how to diagnose what's going on here?


Since a record can legitimately expand over more than one line, you
can't just load the file into an editor and go to line X. I'm not sure
about how fgetcsv() works but it's possible that calling ftell($handle)
allows you to keep track of the file position where each loop starts
reading from. You can then fseek() and fread() to print the file
fragment for manual inspection.

(I suppose that you already thought about using var_dump() to print/log
the output of successful calls and identify the first broken record.)




--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: String Question
Next Topic: copy data from one table to another table
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 18:41:50 GMT 2024

Total time taken to generate the page: 0.04282 seconds