note 68993 deleted from function.nl2br by googleguy

From: Date: Thu, 13 Jun 2013 11:05:58 +0000
Subject: note 68993 deleted from function.nl2br by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195156@lists.php.net to get a copy of this message
Note Submitter: Moore (at) Hs-Furtwangen (dot) De ---- 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.

« previous php.notes (#195156) next »