Re: Trying To Read - Show A Csv File Line By Line

From: Date: Sat, 21 Mar 2009 05:08:23 +0000
Subject: Re: Trying To Read - Show A Csv File Line By Line
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-290466@lists.php.net to get a copy of this message
The for loop iterates through each field of each line, the while loop iterates through each line. Move the <br /> out of the for loop, right before the end of the while loop as follows: <?php $row = 1; $handle = fopen("try3.csv", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . " "; // This will separate each field with a space. } echo "<br />\n"; } fclose($handle); ?> Hmmm - when I tried this example on the link - it echoed every field on it's > own line - but did NOT recognize the returns (each row) of the csv... You will only see the newline characters when viewing the html source, not in the output of the html in the browser. - Tom Friedhof On Fri, Mar 20, 2009 at 5:01 PM, revDAVE <Cool@hosting4days.com> wrote: > On 3/20/2009 2:37 PM, "Kirk.Johnson@zootweb.com" <Kirk.Johnson@zootweb.com > > > wrote: > > > revDAVE <Cool@hosting4days.com> wrote on 03/20/2009 03:11:00 PM: > > > >> Newbie ... I'm trying to Trying to read / show a csv file line by line > > ... > > > > fgetcsv is your friend. > > > > http://us.php.net/manual/en/function.fgetcsv.php > > Thanks Kirk for your help.... > > Hmmm - when I tried this example on the link - it echoed every field on > it's > own line - but did NOT recognize the returns (each row) of the csv... > > Q: how do I just pull out 1 whole row at a time? > > > > <?php > $row = 1; > $handle = fopen("try3.csv", "r"); > while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { > $num = count($data); > echo "<p> $num fields in line $row: <br /></p>\n"; > $row++; > for ($c=0; $c < $num; $c++) { > echo $data[$c] . "<br />\n"; > } > } > fclose($handle); > ?> > > > > > > -- > Thanks - RevDave > Cool @ hosting4days . com > [db-lists 09] > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#290466) next »