Page 1 of 1

html table &nbsp insert failed

Posted: Mon Nov 10, 2008 9:21 am
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

    Re: html table &nbsp insert failed

    Posted: Mon Nov 10, 2008 9:23 am
    by papa
    echo "&nbsp;";

    Re: html table &nbsp insert failed

    Posted: Mon Nov 10, 2008 8:43 pm
    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.