|HTML as plain text|
I want to display some text that can have tags in it, but showing has plain-text, e.g.
I've tryed <pre> and <code> but won't do...
Welcome to the forums, amsmota.
You can replace the
In HTML 3.2 there was the
<xmp> tag which most browsers took to meaning that the contents should be unparsed, but the tag was deprecated and it probably isn't a good idea to depend on this behavior (which was not explicitly defined as such in the HTML 3.2 specification anyway).
Thanks, i'll look into it... For now i just put the all thing in a <textarea> but i don't know if it's ok this way.
Thanks a lot.
First of all, welcome to webmasterworld, amsmota!
I agree with encyclo about using entities like < and >
In fact, entities where created with two purposes:
1: Allow 'stable' use of non-english characters (like ˝, š, Ó ˇ and so on) and simbols that are not included in the 7-bit classic ASCII, to avoid misinterpretations among diferent language clients.
2: (The one that affects you) Allow use of 'reserved' characters, that is to get symbols like < and > shown instead of parsed.
So, I strongly encourage you to use entities for this, because they where created for this.
Hoping be useful,
PS: Everything about entities is published at [w3.org...] You may also seek the W3 Consortium specs to check entitites in the diferent versions of HTML. Even so, the ones you may need are also the ones most used and widely available: < for <, > for >, and don't forget to use & for &, or the system might try to parse following text as an entity. Also care that these entities should be used even in tag's parameters, for example encoding the & in URI's.
Edited by Herenvardo. Edit reason: 'PS' added.
Allright, thanks all for your help.
I just ended using jakarta commons StringEscapeUtils, that does exactly that...
Re. using entities like < and >
TIP: If you use DreamWeaver you can paste the code directly into the 'Design view' and DW will convert the code into things like < and >