Re: how to read text file one line at a time

From: Date: Tue, 19 Nov 2002 20:49:51 +0000
Subject: Re: how to read text file one line at a time
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-125145@lists.php.net to get a copy of this message
even further, instead of using fgets() to get each line and then exploding it, you can use fgetcsv() which reads the line and breaks it into chunks by any delimiter, returning the chunks in an array. $fp = fopen($filename, "r"); while (!feof($fp)) { $line = fgetcsv($fp, 99999, "|"); ... } fclose($fp); "Rasmus Lerdorf" <rasmus@php.net> wrote in message news:Pine.LNX.4.44.0211191142250.4274-100000@www.lerdorf.com... > $array = file($filename); > > Each line of the array will have a line of your file. > > Or, if you want to do it line by line: > > $fp = fopen($filename,'r'); > while(!feof($fp)) { > $line = fgets($fp); > } > fclose($fp); > > -Rasmus > > On Tue, 19 Nov 2002, Kelly Meeks wrote: > > > here's an example of a text file I need to read... > > > > abcd|test1|morevalues|otherstuff > > efghijklm|a;kd;laskf;alskdjf;alskdf;askldjasldkf|;askd;lakjl;asdf|al;sdjf;al f > > > > I believe each line is seperated by a carriage return. > > > > How can I read this in one line at a time in to a variable? > > > > I'm assuming that I could then explode that variable using the pipe as the seperator text? > > > > Kelly > > >

« previous php.general (#125145) next »