Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    86
    Thanks
    0
    Thanked 2 Times in 2 Posts

    htmlspecialchars perl equivalent?

    I'm working on an old perl ftp manager that sometimes doesn't render the html source completely. Where I run into a problem is when I go to edit a page that has a textarea inside of it. The editer sees the pages closing </textarea> tag and then renders the rest of the html source to the browser instead of the page contents. I know how to fix this with php by using:

    $string = htmlspecialchars($string);

    But have know idea how to do this with perl.

    This is what my code looks like where the source gets outputed to the edit textarea.

    Code:
    <textarea cols="70" rows="30" name="file_content">
    EOT
    print while (<FILE>);
    print <<"EOT";
    </textarea>
    Could somebody please show me a solution?

    Thanks.
    Last edited by Jinxy; 05-26-2011 at 05:18 PM.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,871
    Thanks
    2
    Thanked 164 Times in 159 Posts
    I assume you're using the CGI module.
    Code:
    $escaped_string = escapeHTML("unescaped string");
    http://search.cpan.org/~markstos/CGI...OESCAPING_HTML

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    86
    Thanks
    0
    Thanked 2 Times in 2 Posts
    If the script isn't using the CGI module, I'll add it.

    How do I turn this into a string to escape it?

    print while (<FILE>);

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    68
    Thanks
    0
    Thanked 28 Times in 28 Posts
    Code:
    print escapeHTML($_) while (<FILE>);
    - Miller

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    86
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Thanks so much guys! I got an error at first with this but after a google search, I ended up with this.

    Code:
    print CGI::escapeHTML($_) while (<FILE>);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •