note 68841 added to function.sprintf
| From: | dot) | Date: | Sat, 12 Aug 2006 18:54:42 +0000 |
| Subject: | note 68841 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115844@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.224.134.127
----
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.sprintf.php
Edit -- https://master.php.net/note/edit/68841
Del: integrated -- https://master.php.net/note/delete/68841/integrated
Del: useless -- https://master.php.net/note/delete/68841/useless
Del: bad code -- https://master.php.net/note/delete/68841/bad+code
Del: spam -- https://master.php.net/note/delete/68841/spam
Del: non-english -- https://master.php.net/note/delete/68841/non-english
Del: in docs -- https://master.php.net/note/delete/68841/in+docs
Del: other reasons-- https://master.php.net/note/delete/68841
Reject -- https://master.php.net/note/reject/68841
Search -- https://master.php.net/manage/user-notes.php