html table &nbsp insert failed

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

html table &nbsp insert failed

Post by barramundi9 »

Hi, all

Desired output (with table border around them):

see desired_result.png


Actual output (with table border around them):

see actual_result.png


My code:

$myfile = "/tmp/site_survey";

if (file_exists($myfile)) {
$file_handle = fopen($myfile,rb);

fgets($file_handle); //skip the first line
echo "<table border = 2>";

while (!feof($file_handle)) {
$line_of_text = fgets($file_handle);

$tok = strtok($line_of_text," ");

echo "<tr>";

while ($tok) {
echo "<td>";
if (empty($tok)) {
echo "&nbsp";
} else {
echo "$tok";
$tok = strtok(" ");
}
echo "</td>";
}
echo "</tr>";
}

fclose($file_handle);
echo "</table>";
} else {
print "File doesn't exist!";
}


The echo &nbsp seems to be failed, does anyone know why? Any help is appreciated, thanks
    Attachments
    actual_result.png
    actual_result.png (87.52 KiB) Viewed 47 times
    desired_result.png
    desired_result.png (60.69 KiB) Viewed 47 times
    Last edited by barramundi9 on Mon Nov 10, 2008 9:32 am, edited 1 time in total.
    User avatar
    papa
    Forum Regular
    Posts: 958
    Joined: Wed Aug 27, 2008 3:36 am
    Location: Sweden/Sthlm

    Re: html table &nbsp insert failed

    Post by papa »

    echo "&nbsp;";
    barramundi9
    Forum Newbie
    Posts: 3
    Joined: Tue Nov 04, 2008 8:38 am

    Re: html table &nbsp insert failed

    Post by barramundi9 »

    Thanks for replying, but it's not that ~

    I think because I use space as delimiter, so

    if (empty($tok)) {
    echo "&nbsp";
    }

    doesn't work ...

    Any thoughts? Thanks.
    Post Reply