What's wrong with my loop?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barramundi9
Forum Newbie
Posts: 3
Joined: Tue Nov 04, 2008 8:38 am

What's wrong with my loop?

Post by barramundi9 »

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 "&nbsp";
} 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: What's wrong with my loop?

Post by Mark Baker »

Read the manual page for strtok more carefully to see exactly how it should be used

And consider using explode instead
Post Reply