Jump to content

Insert   into empty td tags


killerb

Recommended Posts

I tried writing something to do theis, but you know how it is when you don't have the knowledge. A www search hasn't found anything, so would anyone care to share a preg expression with me?

Just in case a result is empty, the CSS styling in IE needs a non breaking space in the td cell.

Search for td tags containing only whitespace/newline chars.

It will be used like this:

[code]
function assemble_page(){
return preg_replace('search','replace','results from the object methods');
}
// end function
[/code]


Cheers.
Link to comment
https://forums.phpfreaks.com/topic/16279-insert-nbsp-into-empty-td-tags/
Share on other sites

If this is your code, write it to output the nbsp's for you; otherwise:

[code]
<pre>
<?php

$tests = array(
'<td>leave me alone</td>',
'<td align="left">leave me alone too</td>',
'<td style="color:red"></td>',
'<td>i need to be closed',
'<td></td>',
'<td> </td>',
'<td>
</td>'
);

foreach ($tests as &$test) {
echo htmlspecialchars(sprintf('%-40s -> ', $test));
echo htmlspecialchars(preg_replace('%<(td)([^>]*)>\s*</\1>%i', '<\1>&nbsp;</\1>', $test));
echo '<br />';
}
?>
</pre>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.