Re: Trying To Read - Show A Csv File Line By Line
| From: | Virgilio Quilario | Date: | Sat, 21 Mar 2009 10:02:50 +0000 |
| Subject: | Re: Trying To Read - Show A Csv File Line By Line | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-290471@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);
> ?>
>
hi guys,
here is a shortcut to displaying a line of csv.
instead of using for loop, use implode like this.
echo implode(' ', $data) . "<br />\n";
that would display the fields separated by spaces.
Virgil
http://www.jampmark.com