|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80347 nl2br — DOES NOT Insert(s) HTML line breaks before all newlines in a string
Submitted: 2020-11-10 13:13 UTC Modified: 2020-11-10 13:23 UTC
From: mh at phoenixchange dot com Assigned: cmb (profile)
Status: Not a bug Package: Strings related
PHP Version: 7.3.24 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mh at phoenixchange dot com
New email:
PHP Version: OS:


 [2020-11-10 13:13 UTC] mh at phoenixchange dot com
From manual page:

It is not true that: "nl2br — Inserts HTML line breaks before all newlines in a string".  It only does this if the string is double quoted.

Generally perhaps there is no need to point this out, but on the nl2br page it seems a central point.

User 'aabaev' posted the following 1 year ago, but as it's the fifth comment in, past four that are pretty advanced.  I found it only after the penny had finally dropped:

double quotes !== single quotes

php > echo nl2br('\r\n');
php > echo nl2br("\r\n");
<br />

The manual (at string.php) says:

"If the string is enclosed in double-quotes ("), PHP will interpret the following escape sequences for special characters: ...
... Sequence: \n  Meaning: linefeed (LF or 0x0A (10) in ASCII)" 

but nl2br is needed to introduce a LF in this case ...  


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-10 13:23 UTC]
-Status: Open +Status: Not a bug -Package: Documentation problem +Package: Strings related -Assigned To: +Assigned To: cmb
 [2020-11-10 13:23 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

> '\r\n'

There is no newline (neither CR nor LF) in that string.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Apr 10 12:01:23 2021 UTC