note 18301 deleted from function.nl2br by aidan
| From: | aidan@php.net | Date: | Sun, 10 Oct 2004 10:39:34 +0000 |
| Subject: | note 18301 deleted from function.nl2br by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78286@lists.php.net to get a copy of this message | ||
Note Submitter: jroberts [at] forumone [dot] com
----
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)