php / php/php-src

Replace the newlines in nl2br()

未关闭
#15,845 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先在 php-src 中找到 nl2br() 的实现及其测试,然后将当前的插入行为与提议的 replace 参数进行比较。完成的标准是:第三个参数默认保留现有行为,并在启用时替换换行字符,同时覆盖这两种模式。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
backend
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。