Forum Moderators: coopster & phranque

Message Too Old, No Replies

line break

remove line break character from from data

         

LeshanShui

9:04 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



Hi folks:

I was writing a perl CGI processing user input sequence. I run into a problem when I was trying to remove line break character from form data. The output gave one space for each line break. Any idea? Thanks.

Paul Zhang

Mr Anonymous

2:45 am on Sep 27, 2003 (gmt 0)

10+ Year Member



have you tried using the "search and replace" string and leaving no space between the second and third "/"
e.g.

$Your_message=Your Message;
$Your_message=~ s/<br>//g;

claus

2:59 am on Sep 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it's the "newline character" and not the html code for line break, it has it's own code:

\n

Just put this in stead of <br> in Mr_Anomymous' suggestion above.


BTW: Welcome to WebmasterWorld LeshanShui :)

LeshanShui

1:55 pm on Sep 29, 2003 (gmt 0)

10+ Year Member



Thanks for suggestions. I tried s/<br>//g and s/\n//g, and neither solve the problem. Without s/\n//g, one line break was equivalent to two letter spaces. With that, it was equivalent to one letter space. However, it still can not be removed.

Paul

claus

3:48 pm on Sep 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



okay, you might want to use a third line then:

$Your_message=~ s/\n(\n¦\s)?//g;

This translates to: "Remove a linebreak followed by: another linebreak, or a whitespace, or nothing" - the "\s" means "whitespace" and the questionmark makes the expressions in parenthesis optional.

Important: The broken pipe "¦" must be replaced by one you enter from your keyboard, or else it will not work. It must be a solid line and not a broken one.

/claus

timster

7:19 pm on Sep 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> Without s/\n//g, one line break was equivalent to two letter spaces. >> With that, it was equivalent to one letter space.

That sounds like you may have deleted one byte of a 2-byte (Windows) line break.

Maybe try:

s/\r¦\n//gs; # Delete "newlines" and "returns"

or

s/\015¦\012//gs; # Delete CR and LF characters

or

s/[^\S ]//gs; # Delete everything that is whitespace but not a "space"

LeshanShui

7:22 pm on Sep 29, 2003 (gmt 0)

10+ Year Member



Hello folks:

My problem is solved. Two line of code are used:
$mssg =~ s/\n//g;
$mssg =~ s/\s//g;

Note: instead of \s, using an empty space in the second line of code won't work.

Many thanks to everyone.

Paul