note 105133 added to function.nl2br

From: Date: Fri, 29 Jul 2011 14:28:14 +0000
Subject: note 105133 added to function.nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-181994@lists.php.net to get a copy of this message
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> ---- Server IP: 69.147.83.197 Probable Submitter: 212.178.119.238 ---- Manual Page -- http://www.php.net/manual/en/function.nl2br.php Edit -- https://master.php.net/note/edit/105133 Del: integrated -- https://master.php.net/note/delete/105133/integrated Del: useless -- https://master.php.net/note/delete/105133/useless Del: bad code -- https://master.php.net/note/delete/105133/bad+code Del: spam -- https://master.php.net/note/delete/105133/spam Del: non-english -- https://master.php.net/note/delete/105133/non-english Del: in docs -- https://master.php.net/note/delete/105133/in+docs Del: other reasons-- https://master.php.net/note/delete/105133 Reject -- https://master.php.net/note/reject/105133 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181994) next »