note 18301 added to function.nl2br
| From: | jroberts at php2 dot chek dot com | Date: | Thu, 17 Jan 2002 16:33:53 +0000 |
| Subject: | note 18301 added to function.nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24984@lists.php.net to get a copy of this message | ||
You may need to keep in mind the different newline characters (carriage return - CR, and linefeed -
LF) employed by different OS's. Windows uses CRLF (\r\n), Macintosh uses CR (\r), and *nix
systems generally use LF (\n). nl2br() seems to ONLY replace the \n character. If you're
dealing with text that has been created on a Win or Mac box (such as input in an HTML textarea), you
may have \r or \r\n termination on the lines. To replace these with the \n standard, you can use:
$text= preg_replace("/\r\n|\r/", "\n", $text);
- OR -
$text= str_replace('\r\n', '\n', $text);
$text= str_replace('\r', '\n', $text);
(this solution may be faster than the regex)
--
http://www.php.net/manual/en/function.nl2br.php
http://master.php.net/manage/user-notes.php?action=edit+18301
http://master.php.net/manage/user-notes.php?action=delete+18301
http://master.php.net/manage/user-notes.php?action=reject+18301