Welcome to WebmasterWorld Guest from 18.104.22.168
Forum Moderators: incrediBILL
When I display the contents from the database into a textarea of a form I see the encoding, not the HTML source.
for example, I see < instead of <
How do I call the source code into the <textarea> and have it display it as < v. <
Substitute when it comes out
$texfield =~ s/</\<\;/ig;
$texfield =~ s/>/\>\;/ig;
and convert it back when it goes in:
$texfield =~ s/\<\;/</ig;
$texfield =~ s/\>\;/>/ig;
So that when it's called from a "public" page, it displays as expected, yet doesn't screw up the form when you edit it.
Regular expression - How to replace all &'s within an HTML comment [webmasterworld.com]
(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 ;)
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?
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.