Substitution Yah! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Substitution Yah!

davidrtgdavidrtg Posts: 95Member
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.
This isn't working and it looks to be my syntax.
[code]
$test = $form{"event"};
$test ~= s/
/
/g;
$test ~= s/
/
/g;
[/code]
As well, does substitution recognize /r or /n submitted in a textarea?

David

Comments

  • JonathanJonathan Posts: 2,914Member
    : 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
    and
    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
    's and s/
    /
    /g'd it.

    : This isn't working and it looks to be my syntax.
    : [code]
    : $test = $form{"event"};
    : $test ~= s/
    /
    /g;
    : $test ~= s/
    /
    /g;
    : [/code]
    : 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.");

  • davidrtgdavidrtg Posts: 95Member
    : : 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
    and
    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
    's and s/
    //g'd it.
    :
    : : This isn't working and it looks to be my syntax.
    : : [code]
    : : $test = $form{"event"};
    : : $test ~= s/
    //g;
    : : $test ~= s/
    //g;
    : : [/code]
    : : 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
    or
    from the textarea. hrm..
    [code]
    $test =~ s/
    /
    /gs;
    $test =~ s/
    /
    /gs;
    [/code]I'm not sure whether or not a return in a textarea is a
    or
    but i'm thinking its
    , 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.");
    :
    :

  • JonathanJonathan Posts: 2,914Member
    : 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
    or
    from the textarea. hrm..
    : [code]
    : $test =~ s/
    /
    /gs;
    : $test =~ s/
    /
    /gs;
    : [/code]I'm not sure whether or not a return in a textarea is a
    or
    :
    but i'm thinking its
    , 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.");

Sign In or Register to comment.