note 47198 added to function.nl2br
| From: | phpatkeithtylerdotcom at osu1 dot php dot net | Date: | Fri, 05 Nov 2004 18:58:09 +0000 |
| Subject: | note 47198 added to function.nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80166@lists.php.net to get a copy of this message | ||
Take extreme care with nl2br(). It is a simple replacement function -- apparently equivalent to
preg_replace("\n","<br \>\n").
It should not be used on input from HTML textareas, unless all HTML tags are stripped from the input
first. nl2br() does not do anything special to newlines that occur within HTML elements (such as the
<a> anchor tag).
Some browsers will submit textarea data with newlines inserted at the points where the user's
input wrapped to the next line. This can cause anchor links to break and other erratic appearance of
HTML:
<a <br \>href=http://us2.php.net/manual/en/function.nl2br.php>PHP
nl2br()</a>
or worse:
<a href="http://www.site.com/user/page with
<br />spaces.html">URL with spaces</a>
A lot of people use nl2br() to allow their users to insert explicit line and paragraph breaks via
newlines, and their applications will exhibit this problem when used with such browsers.
----
Manual Page -- http://www.php.net/manual/en/function.nl2br.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47198
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47198&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47198&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47198&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47198&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47198&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47198&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47198&report=yes
Search -- http://master.php.net/manage/user-notes.php