I know that this is a common problem with html tables, it's quite difficult to put &nbsp in each empty cell as the cells don't know they're empty till they're sent to the next screen.

I've already tried the CSS way aswell of doing table{empty-cells:show} or similar and this only works in Firefox not IE.

Was wondering if there was some code that could find all the empty cells and put "&nbsp" in them?

Please let me know if you know how this would be done,

Cheers Guys!

    How about:

    $text = preg_replace('#<td([^>])*></td>#i', "<td$1>&nbsp;</td>", $text);
    

      Once I have that code how do i get it to run in the background with everyone else do I just echo $text???

        It's hard to say exactly without knowing what sort of code you want to plug it into. If you currently do something like:

        echo "<tr><td>$var1</td><td>$var2</td></tr>";
        

        You could change it to:

        echo preg_replace('#<td([^>])*></td>#i', "<td$1>&nbsp;</td>", "<tr><td>$var1</td><td>$var2</td></tr>");
        

        Or you could do:

        $var1 = (trim($var1) === "") ? "&nbsp;" : $var1;
        $var1 = (trim($var2) === "") ? "&nbsp;" : $var2;
        echo "<tr><td>$var1</td><td>$var2</td></tr>";
        

        Or, you could make a function:

        function nbsp($text)
        {
           if(trim($text) === "")
           {
              $text = "&nbsp;";
           }
           return($text);
        }
        // then in your output code:
        echo "<tr><td>".nbsp($var1)."</td><td>".nbsp($var2)."</td></tr>";
        

        In other words, there's probably a hundred ways to do it, depending on your specific situation and which techniques you are more comfortable with.

          Write a Reply...