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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.