Perl

Moderators: Jonathan
Number of threads: 1236
Number of posts: 3605

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Substitution Yah! Posted by davidrtg on 13 Dec 2003 at 12:29 PM
I'm saving a textarea to a database which displays the information on a website. I want to substitute the /r or /n that the user enters into the textarea with <br> so its displayed correctly on the webpage.
This isn't working and it looks to be my syntax.
$test = $form{"event"};
$test ~= s/\r/<br>/g;
$test ~= s/\n/<br>/g;

As well, does substitution recognize /r or /n submitted in a textarea?

David
Report
Re: Substitution Yah! Posted by Jonathan on 13 Dec 2003 at 2:39 PM
: I'm saving a textarea to a database which displays the information
: on a website. I want to substitute the /r or /n that the user enters
: into the textarea with so its displayed correctly on the webpage.
Note that if you replace \r and \n and someone posts it from a Windows box then you may well end up with double line breaks. Last time I did this I stripped out all \r's and s/\n/<br>/g'd it.

: This isn't working and it looks to be my syntax.
:
: $test = $form{"event"};
: $test ~= s/\r/<br>/g;
: $test ~= s/\n/<br>/g;
: 

: As well, does substitution recognize /r or /n submitted in a
: textarea?
That should be =~, not ~=. Other than that, it should work but see what I said earlier.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: Substitution Yah! Posted by davidrtg on 13 Dec 2003 at 4:59 PM
: : I'm saving a textarea to a database which displays the information
: : on a website. I want to substitute the /r or /n that the user enters
: : into the textarea with so its displayed correctly on the webpage.
: Note that if you replace \r and \n and someone posts it from a Windows box then you may well end up with double line breaks. Last time I did this I stripped out all \r's and s/\n//g'd it.
:
: : This isn't working and it looks to be my syntax.
: :
: : $test = $form{"event"};
: : $test ~= s/\r//g;
: : $test ~= s/\n//g;
: : 

: : As well, does substitution recognize /r or /n submitted in a
: : textarea?
: That should be =~, not ~=. Other than that, it should work but see what I said earlier.
:
Thanks for showing me the errors in my ways Jonathan! I've now changed it to the following but it still doesn't want to recognize the \n or \r from the textarea. hrm..
$test =~ s/\r/<br>/gs;
$test =~ s/\n/<br>/gs;
I'm not sure whether or not a return in a textarea is a \r or \n but i'm thinking its \r, thats why I am using both atm.

Thanks again!
David

: Jonathan
:
: ###
: for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
: (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
: /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
:
:

Report
Re: Substitution Yah! Posted by Jonathan on 14 Dec 2003 at 8:03 AM
: Thanks for showing me the errors in my ways Jonathan! I've now
: changed it to the following but it still doesn't want to recognize
: the \n or \r from the textarea. hrm..
:
: $test =~ s/\r/<br>/gs;
: $test =~ s/\n/<br>/gs;
: 
I'm not sure whether or not a return in a textarea is a \r or
: \n but i'm thinking its \r, thats why I am using both atm.
Not sure you need the s modifier on the end there. Other than that, I'm not entirely sure. The code you have should in theory work. I'd take a look at the exact contents of $test before the substitution and check that it does contain newline characters etc as you expect (write it to a file or print it or something). I don't know what form parsing code you use. I would expect what you put to work, it certainly matches what I've done in the past.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.