CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
textarea filed - replace new lines with <br>?

 



weatherboy
Novice

Sep 13, 2002, 2:53 PM

Post #1 of 6 (1534 views)
textarea filed - replace new lines with <br>? Can't Post

I just read a thread from 2000 on how to strip out line returns inside a textarea form field. Which is great, except I'm saving the input and feeding it back in html, and wanna add either <br> or a <p> between each return.

Here was the final solution to that thread:

foreach $field (@db_user_definable_field_order)
{
$form_data{$field} =~ s/(\|)|(\n)//g;
# removes pipes, removes returns
}

But I wanna replace the \n's with <br>'s, and I'm not doing it in a for loop - just to one input field... any quick fixes here?
"I know nothink"
- Schulz, Hogan's Heroes


davorg
Thaumaturge / Moderator

Sep 13, 2002, 3:18 PM

Post #2 of 6 (1533 views)
Re: [weatherboy] textarea filed - replace new lines with <br>? [In reply to] Can't Post


Code
$text =~ s/\cM\cJ?/<br>/g;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


(This post was edited by davorg on Sep 13, 2002, 11:19 PM)


Paul
Enthusiast

Sep 13, 2002, 3:19 PM

Post #3 of 6 (1532 views)
Re: [davorg] textarea filed - replace new lines with <br>? [In reply to] Can't Post

Or

$text =~ s/\r?\n/<br>/g;


(This post was edited by RedRum on Sep 13, 2002, 3:20 PM)


davorg
Thaumaturge / Moderator

Sep 13, 2002, 3:30 PM

Post #4 of 6 (1527 views)
Re: [RedRum] textarea filed - replace new lines with <br>? [In reply to] Can't Post

I try to avoid using "logical" escape sequences like those when I'm not sure which platform I'm running on as the meaning of \n changes on different platforms.

I find it safer to use the actual control characters or ASCII characters.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


weatherboy
Novice

Sep 13, 2002, 5:39 PM

Post #5 of 6 (1523 views)
Re: [davorg] textarea filed - replace new lines with <br>? [In reply to] Can't Post

Either option isn't working. All I get is the same string of numbers everytime.

Here's what I'm using:

#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse(*input);

$note_content = $input{'noteContent'};

if($note_content){
$note_content = ~ s/\r?\n/<br>/g;
}

$thisClient = $input{'passedClient'};
$note_adder = $input{'note_adder'};
$note_date = $input{'noteDate'};
$this_note_id = $input {'noteID'};



NOTE CONTENT should return the input ... but instead I just get numbers... what's up with that?
"I know nothink"
- Schulz, Hogan's Heroes


davorg
Thaumaturge / Moderator

Sep 13, 2002, 11:26 PM

Post #6 of 6 (1512 views)
Re: [weatherboy] textarea filed - replace new lines with <br>? [In reply to] Can't Post

Yeah, there was a typo in my answer - the =~ operator got separated into two pieces.

I've corrected it, please try it again.

Oh, and _please_ don't use cgi-lib.pl. It's very old. Use CGI.pm instead.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives