php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66426 nl2br option to replace html5 newlines
Submitted: 2014-01-06 15:29 UTC Modified: 2014-01-07 07:58 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: hajo at csphere dot eu Assigned:
Status: Open Package: Strings related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2014-01-06 15:29 UTC] hajo at csphere dot eu
Description:
------------
copied from the documentation nl2br can replace the following:

\r\n, \n\r, \n und \r

it might be an improvement if it can also replace the html5 entity &newline;

e.g. when htmlentities is used with ENT_HTML5 and nl2br afterwards all newlines are no longer replaced due to the ENT_HTML5 flag, but with all other flags this works. with htmlspecialchars this even works with the ENT_HTML5 flag as its not replacing that much entities.

an alternative would be to provide an option to skip or change the &Newline; entity more easily. this ticket is just opened to suggest a way to ease the use of nl2br regarding html5.

Test script:
---------------
$test = "abc\n"defg";

$escape = htmlentities($test, ENT_HTML5);

$result = nl2br($escape);

Expected result:
----------------
var_dump($result); // string "abc&Newline;<br />defg"

Actual result:
--------------
var_dump($result); // string "abc&Newline;defg"

Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC