note 10340 added to nl2br
| From: | bill at websitecreations dot net | Date: | Fri, 29 Dec 2000 06:35:02 +0000 |
| Subject: | note 10340 added to nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-9290@lists.php.net to get a copy of this message | ||
Koaps,
Thanks for your example above but shouldn't the line with nl2br be;
$text = nl2br($text);
I tried it without the $ and it did not work for me.
For those of you who are lost about nl2br, this is what I did and it works. I am teaching myself PHP
and n2lbr has had me baffled for nearly 2 weeks. But tonight, I had a breakthrough thanks to the guy
who posted above me (koaps).
In my scenario, I have users type info into a form and the info is written to a DB. I then take this
data from the database and display it on a web page. My variable in this case is $input. $input
holds the content that the user typed into the form. I want to display this content with the line
breaks. Thus;
print("<pre>");
$input = nl2br($input);
$input = ereg_replace("\n", "", $input);
$input = ereg_replace("\r", "", $input);
print ("</pre>");
print "Thanks for the info. This is the info you entered into the
form<br><br>$input";
-----------
Thus, the output on the page is parsed correctly with linebreaks included.
-----------
Thanks for the info. This is the info you entered into the form
The text here would be from the variable called input.
Because I used n2lbr, the linebreaks are included just as the user had intended.
What a relief to finally have figured out n2lbr.
-------
Happy coding!
Bill M
http://www.php.net/manual/function.nl2br.php