I have a stupid problem that I just can't seem to get my arms around, so I'm hoping someone here with a lot more experience (or even just a little would probably do the trick ;-p) can give me a little direction.

I have a script that allows users to modify HTML pages in a textarea field of a forum. The content is displayed in a <textarea> field of an HTML form, and they can then submit the changes.

I'm encountering a problem when the HTML content to be edited contains a </textarea> tag, since when the form attempst to fill the HTML content into the textarea, when the closing tag is printed, it closes the text area that the HTML content is suppose to fill into, and the rest of the HTML content is displayed on the page as if it were being viewed.

If that was clearly explained, please let me know & I'll try to be more clear.

Anyway, one way I've found around this is by adding at the end... since this tells the browser not to treat it as displayable content and thus prints the entire content in the <textarea>

So, basically I have this:

my $content; open (FILE,"file.html"); while (<FILE>) { $content .= $_; } close(FILE);

which grabs the html file to be edited

$content = "<!--\n" . $content . "\n-->";

which allows it to be displayed properly into the textarea field, even if the HTML content contains a </textarea> tag.
then once it's submitted:

my $content = param('content'); $content =~ s/<!--\n//; $content =~ s/\n-->//;

which grabs the content that the user is submitting, and then attempts to remove the content that was added automatically to preven the problem mentioned earlier.
open (FILE,">file.html"); print FILE $content; close(FILE);

which saves the modified file.

Now, first I'll acknowledge that this is probably a stupid way to attempting to fix this problem. If anyone has any other suggestions, I'm definetly open to them.
If no other suggestions, could anyone tell me why the substitution for the strings is not functioning? It ignores them, and they end up being written to the file (when I actually want them removed prior to the file being written to).

Any help would be GREATLY appreciate.

Thx all,
Stenyj

In reply to escaping <!-- and --> in substitution...or other help plz by Stenyj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.