Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 ( #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;


Comment on Re: Replacing new lines in multi line text box form fields with <br>.
Download Code
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
Node Status?
node history
Node Type: note [id://410519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2015-07-28 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls