I don't see why your substitutions aren't being made; it seems to work for me in a simple example.
As far as other methods: I've faced exactly that sort of
problem, and what I've done usually is to make some kind of
substitution, e.g. substituting </textarea> with #%#%#%textarea#%#%#% so that the term isn't interpreted by the browser and then substituting back before writing out the result. Actually, I've mostly done this in inputs of type
"hidden" so it isn't visible to the user, but occasionally
I've done it in visible areas (e.g. in email headers where
diamond brackets occur and I want to see the information in an html page, I might substitute diamond brackets for square brackets and later substitute back.)
I know this sounds lame brained, but sometimes I couldn't
find any other easy way around the problem, and this type
of solution always seemed to work with no problems (for years!) I'm sure someone will point out that if the text
really contained #%#%#%textarea#%#%#% then the substitution I mentioned will break, but I guess I can live with that possibility.
Your solution seems to be something of the same type, but don't you need to worry about possibly removing comment markers that you don't want removed? By the way, I think that <!-- is supposed to be followed by a space to be proper html and similarly the ending marker should be preceeded by a space.
chas
(Update: The method I describe works if the users know that
the strange constructions shouldn't be altered. If a large
class of users can do the editing, it's probably not a
great idea for them to be visible. Usually, I arrange
things so the strange stuff isn't actually in the texareas,
possibly by splitting things into several textareas. Of
course, it often isn't a good idea to let arbitrary users
edit html tags at all since they may not do it properly -
restrict access to just text blocks.)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.