[php-src] Issue #15845: Replace the newlines in nl2br()

From: Date: Wed, 11 Sep 2024 21:34:26 +0000
Subject: [php-src] Issue #15845: Replace the newlines in nl2br()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247761@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/15845 Author: fredericch ### Description The function name of nl2br() suggests that it is a "replace" operation but is actually an "insert" operation. Would it be possible to add a 3rd parameter so the function would actually replace the newline characters? nl2br(string $string, bool $use_xhtml = true, bool $replace = false): string The confusion with the name and the need for the 3rd parameter is obvious in the user contributed notes (most popular one and following ones): https://www.php.net/manual/en/function.nl2br.php#49516 The advantage of the 3rd parameter: - nl2br() would be idempotent when 3rd parameter is set to true. Today n2br() cannot be applied several times to a string without managing extra inserts. - Simplify the code. Remove the wrappers to replace the newlines. - Flexibility. Old behavior could be kept. - Backward compatible.

« previous php.bugs (#247761) next »