Replace the newlines in nl2br()
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the nl2br() implementation and its tests in php-src, then compare the current insertion behavior with the proposed replace parameter. Done means the third parameter preserves existing behavior by default and replaces newline characters when enabled, with coverage for both modes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100