Jump to content

Archived

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

killerb

Insert   into empty td tags

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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Updated version that retains the classNames:

[code]
<?php

$pageContent .= preg_replace('%<(td)([^>]*)>\s*</\1>%i', '<\1\2>&nbsp;</\1>', show_message().$passedContent.$this->content);

?>
[/code]

Cheers

Share this post


Link to post
Share on other sites

×

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.