php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mh at phoenixchange dot com
New email:
PHP Version: OS:

 

 [2020-11-10 13:13 UTC] mh at phoenixchange dot com
Description:
------------
---
From manual page: https://php.net/function.nl2br
---

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');
\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 ...  



Patches

Pull Requests

History

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

> '\r\n'

There is no newline (neither CR nor LF) in that string.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC