php / php/php-src

Replace the newlines in nl2br()

Offen
#15,845 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Extension: standard Feature Status: Needs Triage
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die Implementierung von nl2br() und ihre Tests in php-src zu finden, und vergleiche anschließend das aktuelle Einfügeverhalten mit dem vorgeschlagenen replace-Parameter. Als erledigt gilt die Änderung, wenn der dritte Parameter standardmäßig das bestehende Verhalten beibehält und bei Aktivierung Zeilenumbruchzeichen ersetzt, mit Abdeckung beider Modi.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.