Req #64639 [Com]: Add third parameter to nl2br
| From: | narf at devilix dot net | Date: | Thu, 06 Mar 2014 12:30:15 +0000 |
| Subject: | Req #64639 [Com]: Add third parameter to nl2br | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184563@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64639&edit=1
ID: 64639
Comment by: narf at devilix dot net
Reported by: valentiny510 at yahoo dot es
Summary: Add third parameter to nl2br
Status: Open
Type: Feature/Change Request
Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
The bigger issue here is how you'd reverse the process. Without knowing that the function just
adds instead of replacing, one would try the following:
function br2nl($string, $is_xhtml = TRUE)
{
return str_replace(
$is_xhtml ? '<br />' : '<br>',
PHP_EOL
);
}
The problem is that this would result in doubling the newline characters.
Previous Comments:
------------------------------------------------------------------------
[2013-07-13 01:42:30] valentiny510 at yahoo dot es
As additional note..
If I can have linebreaks and nicely formated text in just one function, why don't do'it ?
I don't think is such a big deal, or should change the name to something like
"addbr2nl", it will be more "correct"..
------------------------------------------------------------------------
[2013-07-13 01:33:11] valentiny510 at yahoo dot es
Nikic, 2 booleans parameters for you are "too many unclear boolean parameters"
LOL...
------------------------------------------------------------------------
[2013-05-03 08:13:28] nikic@php.net
In my eyes this is an unnecessary change. nl2br handles the common case, where you want to have
linebreaks displayed and have the code nicely formatted at the same time. This is what nl2br does
and I don't think it need to do any more.
I don't see why we should add support for incorrect usages of the function inside <pre>.
And in any case, if you should have need for this (for whatever odd reason), then it is trivial to
write yourself. Quite honestly I think that preg_replace('#([\r?\n]+)#',
'<br>', $string) is a good bit clearer than nl2br($string, false, true). That's
just too many unclear boolean parameters.
------------------------------------------------------------------------
[2013-05-03 07:01:13] octavianmarinescu at tavi dot ro
yes would be a shorter and more elegant solution
nl2br($str, false, true);
nice and clean..
------------------------------------------------------------------------
[2013-04-17 19:44:35] krakjoe@php.net
The following patch has been added/updated:
Patch Name: nl2br_additional_parameter
Revision: 1366227875
URL: https://bugs.php.net/patch-display.php?bug=64639&patch=nl2br_additional_parameter&revision=1366227875
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=64639
--
Edit this bug report at https://bugs.php.net/bug.php?id=64639&edit=1