note 68993 added to function.nl2br

From: Date: Fri, 18 Aug 2006 18:13:14 +0000
Subject: note 68993 added to function.nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-116044@lists.php.net to get a copy of this message
Here a litle function that might come handy one time: It gives back a String and adds a <BR> (you can change it to <br />) to every line end. And it adds $num blanks to the front of the next line. <?php function nl2brnl($text, $num) { return preg_replace("/\\r\\n|\\n|\\r/", sprintf("% -".(5+$num)."s","<BR>\\n"), $text); } $a = " one\\n two\\r\\n three"; $b = nl2brnl($a, 2); var_dump($b); /* output will be: string(30) " one<BR> two<BR> three" */ echo " <P>\\n "; echo $b /* output will be: <P> one<BR> two<BR> three */ ?> Is helpfull for avouding code_soup. ---- Server IP: 217.160.72.57 Probable Submitter: 217.80.87.214 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.nl2br.php Edit -- https://master.php.net/note/edit/68993 Del: integrated -- https://master.php.net/note/delete/68993/integrated Del: useless -- https://master.php.net/note/delete/68993/useless Del: bad code -- https://master.php.net/note/delete/68993/bad+code Del: spam -- https://master.php.net/note/delete/68993/spam Del: non-english -- https://master.php.net/note/delete/68993/non-english Del: in docs -- https://master.php.net/note/delete/68993/in+docs Del: other reasons-- https://master.php.net/note/delete/68993 Reject -- https://master.php.net/note/reject/68993 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116044) next »