Doc #80347 [Opn->Nab]: nl2br — DOES NOT Insert(s) HTML line breaks before all newlines in a string

From: Date: Tue, 10 Nov 2020 13:23:16 +0000
Subject: Doc #80347 [Opn->Nab]: nl2br — DOES NOT Insert(s) HTML line breaks before all newlines in a string
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18112@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80347&edit=1

 ID:                 80347
 Updated by:         cmb@php.net
 Reported by:        mh at phoenixchange dot com
 Summary:            nl2br — DOES NOT Insert(s) HTML line breaks before
                     all newlines in a string
-Status:             Open
+Status:             Not a bug
 Type:               Documentation Problem
-Package:            Documentation problem
+Package:            Strings related
 PHP Version:        7.3.24
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2020-11-10 13:13:38] 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 ...  




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80347&edit=1


Thread (2 messages)

« previous php.doc.bugs (#18112) next »