Page is a not externally linkable
penders - 3:26 pm on Jun 4, 2008 (gmt 0)
Regular expression - How to replace all &'s within an HTML comment [webmasterworld.com] <edit> Just to note... If you are allowing your users to enter HTML source to be saved as is (including entities), you probably don't need to 'convert this back' before saving? Or are there special cases?
I think you'll need to essentially 'double-encode' your html entities before outputting to the textarea. Essentially converting all '&' into '&'. However, there is a bit of a cross-browser issue if you have html entities within html comments - a problem I had a short while back... see this thread for more info and my post at the end for an explanation of your problem...
(an HTML source code editor...) The HTML content is loaded into a <textarea> to be edited. HTML entities, however, get converted by the browser into the actual characters for display so the HTML entity is lost. So < is converted into &lt; so that it actually displays in the textarea as <. However, I've found that in IE and FF HTML entities that appear within HTML comments do not get converted into the actual characters, they stay as HTML entities (hence this thread), except in Opera they do (hhmmmm)!
(I think rocknbil types quicker than me ;)
eg. < gets converted to &lt; before writing it out to your page server-side (between <textarea> tags). This displays correctly as < on the client side and this should get returned as-is to get plugged back into your database.