note 10384 deleted from nl2br by zak
| From: | zak@php.net | Date: | Wed, 03 Jan 2001 01:34:14 +0000 |
| Subject: | note 10384 deleted from nl2br by zak | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-9300@lists.php.net to get a copy of this message | ||
Ah, looks like someone erased my other example. Well, here it is again.
Usage of nl2br to display data on a web page after retrieving from a database. Usually, the data
strips all line breaks and the text runs together. nl2br will put the line breaks back in.
Example, say your variable is $theText and this variable holds a couple of paragraphis of info. To
display it properly with line breaks, use this format;
$theText = nl2br($theText);
$theText = ereg_replace("n", "", $theText);
$theText = ereg_replace("r", "", $theText);
$theText = ereg_replace("'", "'", $theText);
PRINT "$theText";
-----
Thus, the output will include line breaks. Also note the following line from above
$theText = ereg_replace("'", "'", $theText);
Which replaces the single quote with the character code. Otherwise, all text after a single quote
will be lost.