looping problem?
From: Jas (jason.gerfen_at_scl.utah.edu)
Date: 12/30/03
- Next message: Mike Migurski: "Re: [PHP] looping problem?"
- Previous message: Philip Pawley: "RE: [PHP] Migrating from SSI and Perl"
- Next in thread: Mike Migurski: "Re: [PHP] looping problem?"
- Reply: Mike Migurski: "Re: [PHP] looping problem?"
- Reply: Hitek: "Re: [PHP] looping problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: php-general@lists.php.net Date: Tue, 30 Dec 2003 09:10:14 -0700
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
- Next message: Mike Migurski: "Re: [PHP] looping problem?"
- Previous message: Philip Pawley: "RE: [PHP] Migrating from SSI and Perl"
- Next in thread: Mike Migurski: "Re: [PHP] looping problem?"
- Reply: Mike Migurski: "Re: [PHP] looping problem?"
- Reply: Hitek: "Re: [PHP] looping problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]