-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Description
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 advantages of the 3rd parameter (instead of changing the behavior):
- 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. We could remove the wrappers to replace the newlines from our code.
- Flexibility. Old behavior could be kept.
- Backward compatible.