Opened 4 years ago
Last modified 12 months ago
#51040 new feature request
How about having a native BR to Newline method, i.e. br2nl
Reported by: | subrataemfluence | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Formatting | Keywords: | 2nd-opinion reporter-feedback |
Focuses: | Cc: |
Description
Is there a specific reason that WordPress does not have yet (?) a function to convert Line break (<Br />
) to Newline (\n
)?
This is useful for textarea
fields.
One of the use cases could be a multiline address used as metadata in the user profile.
In the textarea
user enters like:
Building name <Return> Street address <Return> Postal code. Country name
When saved we usually convert all line breaks into HTML line breaks for easier rendering in the front-end. We do this using nl2br
method. So in the database, the above becomes:
Building name <br /> Street address <br /> Postal code. Country name
However, when the above information is populated in edit mode, it comes up like
Building name <br /> Street address <br /> Postal code. Country name.
A br2nl
method will make life much easier.
<?php /** * @param string $input_string * Converts HTML line break (<br />) into newline character (\n) * * @return null|string|string[] * Since 5.5 */ function br2nl( $input_string ) { return preg_replace('/<br\s?\/?>/ius', "\n", str_replace( "\n", "", str_replace( "\r", "", htmlspecialchars_decode( $input_string ) ) ) ); }
Change History (4)
#3
follow-up:
↓ 4
@
4 years ago
- Component changed from General to Formatting
- Type changed from enhancement to feature request
- Version 5.5 deleted
@subrataemfluence This was a spam comment.
#4
in reply to:
↑ 3
@
4 years ago
Thank you @johnbillion for taking immediate action and removing the link :)
Replying to johnbillion:
@subrataemfluence This was a spam comment.
#5
@
12 months ago
- Keywords reporter-feedback added
@subrataemfluence
When saved we usually convert all line breaks into HTML line breaks for easier rendering
In my tests, when I save multiline text, it is saved as is, without the <br>
characters.
Also, nl2br()
doesn't seem to be used by Core.
Are you reffering to some custom code?
Additionally, there has been no activity on this ticket for the past three years.
Could it be closed in case it's no longer relevant?
What's happening here?! I request the concerned team take necessary action ikmmediately, please.
Replying to techunz:
~link removed~