Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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
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 surveying the Monastery: (13)
As of 2014-12-19 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (83 votes), past polls