Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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?
[Discipulus]: get them all printed on screen
Discipulus ;=)
[shmem]: silly question, silly answer:
[Discipulus]: i know, i know..
[shmem]: man perlfunc |perl -nle '$ok++ if /Alphabetical Listing of Perl Functions/;if($ok ){$s{$1}++if /^ (\w+)/}}{for(keys %s){$f="prototype \\\&CORE::$_"; eval"$f"||delete $CORE::{$_}}print for sort keys%CORE::'
[shmem]: well, there are some builtins which don't have a prototype...
[Discipulus]: eh eh.. i was looking in toke.c but dunno if is already used
[shmem]: oh the whitespace in the regex got condensed, meh

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-05-23 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?