Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

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 romping around the Monastery: (9)
As of 2016-10-01 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (7 votes). Check out past polls.