What's wrong with my loop?
Posted: Tue Nov 04, 2008 8:57 am
Hi, all
I need the following output put into an html table:
Channel RSSI SSID BSSID Enc Auth NetworkType
6 -62 00:19:5b:05:57:dd NONE OPEN Infra
9 -38 wireless 00:01:36:0f:da:90 WEP OPEN Infra
1 -86 Home 00:11:d8:58:a2:c5 NONE OPEN Infra
so I write the following:
$myfile = "/tmp/site_survey";
if (file_exists($myfile)) {
$file_handle = fopen($myfile,rb);
echo "<table border = 2>";
while (!feof($file_handle)) {
$line_of_text = fgets($file_handle);
$word = array();
$word = strtok($line_of_text," ");
echo "<tr>";
for ($i=0; $i<count($word); $i++) {
echo "<td>";
if (empty($word)) {
echo " ";
} else {
echo $word;
}
echo "</td>";
}
echo "</tr>";
}
fclose($file_handle);
echo "</table>";
} else {
print "File doesn't exist!";
}
But the output I'm getting turns is:
Channel
6
9
1
with border around them, but it wouldn't produce the other columns, and if I use $word[$i] instead of $word, it will print individual letters only, like the following:
C
6
9
1
I think there is something wrong with my loop, any help is appreciated, thanks
barramundi9
I need the following output put into an html table:
Channel RSSI SSID BSSID Enc Auth NetworkType
6 -62 00:19:5b:05:57:dd NONE OPEN Infra
9 -38 wireless 00:01:36:0f:da:90 WEP OPEN Infra
1 -86 Home 00:11:d8:58:a2:c5 NONE OPEN Infra
so I write the following:
$myfile = "/tmp/site_survey";
if (file_exists($myfile)) {
$file_handle = fopen($myfile,rb);
echo "<table border = 2>";
while (!feof($file_handle)) {
$line_of_text = fgets($file_handle);
$word = array();
$word = strtok($line_of_text," ");
echo "<tr>";
for ($i=0; $i<count($word); $i++) {
echo "<td>";
if (empty($word)) {
echo " ";
} else {
echo $word;
}
echo "</td>";
}
echo "</tr>";
}
fclose($file_handle);
echo "</table>";
} else {
print "File doesn't exist!";
}
But the output I'm getting turns is:
Channel
6
9
1
with border around them, but it wouldn't produce the other columns, and if I use $word[$i] instead of $word, it will print individual letters only, like the following:
C
6
9
1
I think there is something wrong with my loop, any help is appreciated, thanks
barramundi9