killerb Posted August 2, 2006 Share Posted August 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16279-insert-nbsp-into-empty-td-tags/ Share on other sites More sharing options...
effigy Posted August 2, 2006 Share Posted August 2, 2006 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> </\1>', $test)); echo '<br />'; }?></pre>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16279-insert-nbsp-into-empty-td-tags/#findComment-67529 Share on other sites More sharing options...
killerb Posted August 2, 2006 Author Share Posted August 2, 2006 Exactly what I needed, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/16279-insert-nbsp-into-empty-td-tags/#findComment-67544 Share on other sites More sharing options...
killerb Posted August 2, 2006 Author Share Posted August 2, 2006 Updated version that retains the classNames:[code]<?php$pageContent .= preg_replace('%<(td)([^>]*)>\s*</\1>%i', '<\1\2> </\1>', show_message().$passedContent.$this->content);?>[/code]Cheers Quote Link to comment https://forums.phpfreaks.com/topic/16279-insert-nbsp-into-empty-td-tags/#findComment-67658 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.