Welcome to WebmasterWorld Guest from 54.196.214.35

Forum Moderators: incrediBILL

Message Too Old, No Replies

HTML as plain text

     
6:07 pm on Jul 27, 2005 (gmt 0)

New User

10+ Year Member

joined:July 27, 2005
posts:11
votes: 0


Hi:

I want to display some text that can have tags in it, but showing has plain-text, e.g.

<b>1234</b>

instead of

1234

I've tryed <pre> and <code> but won't do...

Thanks

6:20 pm on July 27, 2005 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 31, 2003
posts:9063
votes: 2


Welcome to the forums, amsmota.

You can replace the

<
and
>
with
&lt;
and
&gt;
respectively:

&lt;b&gt;1234&lt;/b&gt;

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).

<xmp><b>1234</b></xmp>
7:25 pm on July 27, 2005 (gmt 0)

New User

10+ Year Member

joined:July 27, 2005
posts:11
votes: 0


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.

1:42 pm on July 28, 2005 (gmt 0)

Full Member

10+ Year Member

joined:July 7, 2003
posts:282
votes: 0


First of all, welcome to webmasterworld, amsmota!
I agree with encyclo about using entities like &lt; and &gt;
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,
Herenvard÷

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: &lt; for <, &gt; for >, and don't forget to use &amp; 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.

12:09 pm on Aug 2, 2005 (gmt 0)

New User

10+ Year Member

joined:July 27, 2005
posts:11
votes: 0


Allright, thanks all for your help.

I just ended using jakarta commons StringEscapeUtils, that does exactly that...

Thanks.

2:48 pm on Aug 2, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2001
posts:1281
votes: 0


Re. using entities like &lt; and &gt;

TIP: If you use DreamWeaver you can paste the code directly into the 'Design view' and DW will convert the code into things like &lt; and &gt;