开发者

how to display < html tags without escaping nightmare

I want to be able to i开发者_开发问答ndicate a part of the HTML file where i can simply type <asd><qwe> and they will be displayed as such (i mean the text).

I am aware we can do this: <asd><qwe> but it slowly becomes a nightmare..

I tried:

<pre><asd><qwe></pre>

but it isn't working..


HTML 4.x (technically) supports CDATA sections (which do what you want), but browsers don't (except in XHTML served as application/xhtml+xml which isn't supported by IE < 9).

Use &lt; and friends. An editor with Find & Replace stops it being a nightmare.


Why not use an online tool like Quick Escape: http://accessify.com/tools-and-wizards/developer-tools/quick-escape/

Write whatever you would like without escaping it. Then copy and paste it into Quick Escape and it will return it escaped.


Replace all you < by &lt; (lt = less than) and all your > by &gt; (gt = greater than).

If you're using some PHP, you can simply use htmlentities(), which will do that alone.


Escaping HTML special characters (not just < and > but several others as well) is your only option I'm afraid. However there's quite a few editors that can do this for you


Technically you can put you data in a <![CDATA[...]]> construct. However, it is poorly supported by browsers, so you have to live with the escaping. You best option is probably to use an editor that can help you escaping.


Your question is incredible vague but you are probably looking for about the <XMP></XMP> tag set. However, such element has been deprecated for quite long: you can use it for some quick testing but it has no place in a live site.

The only serious approach is to use a server-side language that takes care of escaping for you.


See you have two options :

  • In your text editor "Find and Replace All" all "<" with "<" and all ">" with ">"

  • And as posted by Oltarus, if your server supports php then just use:

    <?php echo htmlentities("<html><head></head></html>"); ?>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜