Replace the newlines in nl2br()
未关闭
还没有人认领这个 Issue。
Extension: standard
Feature
Status: Needs Triage
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 php-src 中找到 nl2br() 的实现及其测试,然后将当前的插入行为与提议的 replace 参数进行比较。完成的标准是:第三个参数默认保留现有行为,并在启用时替换换行字符,同时覆盖这两种模式。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100