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> </td>", "<tr><td>$var1</td><td>$var2</td></tr>");
Or you could do:
$var1 = (trim($var1) === "") ? " " : $var1;
$var1 = (trim($var2) === "") ? " " : $var2;
echo "<tr><td>$var1</td><td>$var2</td></tr>";
Or, you could make a function:
function nbsp($text)
{
if(trim($text) === "")
{
$text = " ";
}
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.