Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Replacing new lines in multi line text box form fields with <br>.

by tachyon (Chancellor)
on Nov 26, 2004 at 06:50 UTC ( [id://410519]=note: print w/replies, xml ) Need Help??


in reply to Replacing new lines in multi line text box form fields with <br>.

Use a character class to deal with LF CR and CRLF line endings. A standard newline after the
maintains readability.
$INPUT{'comments'} =~ s/[\r\n]+/<br>\n/g;

Replies are listed 'Best First'.
Re^2: Replacing new lines in multi line text box form fields with <br>.
by Smylers (Pilgrim) on Nov 26, 2004 at 09:20 UTC
    $INPUT{'comments'} =~ s/[\r\n]+/<br>\n/g;

    That isn't a good pattern to use, because it means that two line-breaks in the input, such as used to indicate a paragraph break, become only one in the output.

    Smylers

      You're right. s/\r\n|\r|\n/<br>\n/g is better.

      cheers

      tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://410519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found