note 105133 deleted from function.nl2br by googleguy
| From: | googleguy@php.net | Date: | Thu, 13 Jun 2013 11:10:19 +0000 |
| Subject: | note 105133 deleted from function.nl2br by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195178@lists.php.net to get a copy of this message | ||
Note Submitter: php at djurredeboer dot nl
----
If you use nl2br over a html table you get a lot of new lines above this table. you can fix it by
using this function
<?php
$input = nl2br("
this is a test<br/>
Aadasd
asda
asd
asd
<table>
<td></td>
<td></td>
<td></td>
</table>");
$output = preg_replace_callback('%<table(.*?)>(.*?)</table>%si',
'delTableBr',$input);
function delTableBr($groups) {
return
'<table'.$groups[1].'>'.preg_replace('/<br[^>]*?>/si',
'',$groups[2]).'</table>';
}
?>
Now it will return
<br />
this is a test<br/><br />
<br />
Aadasd<br />
asda<br />
asd<br />
asd<br />
<table>
<td></td>
<td></td>
<td></td>
</table>