Re: CSV file

From: Date: Wed, 24 Jun 2009 14:17:23 +0000
Subject: Re: CSV file
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-294524@lists.php.net to get a copy of this message
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@php.net> 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 >

« previous php.general (#294524) next »