Re: looping problem?

From: Date: Tue, 30 Dec 2003 19:08:30 +0000
Subject: Re: looping problem?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-173495@lists.php.net to get a copy of this message
Shorter version of the script: <? $line = file("fa.csv"); for($i=0;$i<count($line);$i++){
        $data = explode(",", $line[$i]);
        echo "host $data[0] {<br />\nhardware ethernet $data[1];<br />\nfixed-address $data[2];<br />\n}<br />\n";
} ?> At 08:10 AM 12/30/2003, Jas wrote:
Problem with looping over a CSV file (3 results for each line)? Here is the CSV file contents... MTPC-01,00:02:B3:A2:9D:ED,155.97.15.11 MTPC-02,00:02:B3:A2:B6:F4,155.97.15.12 MTPC-03,00:02:B3:A2:A1:A7,155.97.15.13 MTPC-04,00:02:B3:A2:07:F2,155.97.15.14 MTPC-05,00:02:B3:A2:B8:4D,155.97.15.15 Here is the script... <?php $row = 1; $file = "fa.csv"; $id = fopen("$file","r"); while($data = fgetcsv($id,100,",")) { $num = count($data); $row++;
    for($c = 0; $c < $num; $c++) {
       echo "host $data[0] {<br />\nhardware ethernet $data[1];<br />\nfixed-address $data[2];<br />\n}<br />\n"; }
        }
fclose($id); ?> And this is the output... (notice 3 results for the first line in the CSV file) host MTPC-01 { hardware ethernet 00:02:B3:A2:9D:ED; fixed-address 155.97.15.11; } host MTPC-01 { hardware ethernet 00:02:B3:A2:9D:ED; fixed-address 155.97.15.11; } host MTPC-01 { hardware ethernet 00:02:B3:A2:9D:ED; fixed-address 155.97.15.11; } Any help is appreciated... Jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#173495) next »