If you want to know how many lines there are *before* inserting to the database, you can't count "as you go", you have to either read the file twice or read it once, store it memory in a variable and then insert in the database. On Wed, Jun 24, 2009 at 11:12 AM, Richard Heyes<richard@xxxxxxx> wrote: > Hi, > >> You can read the whole file (file_get_contents) and count the number >> of "\n" in it, or read it line by line with fgets and store the lines >> in an array, and then the number of lines is the count() of the array, >> and you can use that array to store it in the database. > > If you have a billion line CSV then speed may suffer somewhat though. > Best to still use fgets() or fgetcsv() and count as you go. > > -- > Richard Heyes > HTML5 graphing: RGraph (www.rgraph.net - updated 20th June) > PHP mail: RMail (www.phpguru.org/rmail) > PHP datagrid: RGrid (www.phpguru.org/rgrid) > PHP Template: RTemplate (www.phpguru.org/rtemplate) > PHP SMTP: http://www.phpguru.org/smtp > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php