< xmp>的任何替代形式标记以将html呈现为纯文本 [英] any alternative of <xmp> tag to renders html to as plain text

查看:604
本文介绍了< xmp>的任何替代形式标记以将html呈现为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将HTML代码显示为纯文本.
例如

I want to show HTML code as plain text.
for example

<div style="width:250px;">
<xmp>
<a href="#"> new element  dummy text new element  dummy text new element  dummy text new element  dummy text new element  dummy text</a>
</xmp>
<div>

问题是使用<xmp>标记时,它忽略了包含文本的div宽度.我该如何解决.除了<xmp>标签,还有其他解决方案吗?

The problem is while using <xmp> tag its ignore the div width that contain text. How can I fix it out. Any other solution instead of <xmp> tag?

推荐答案

只需使用< xmp>或 <pre>标记不会帮助您将HTML显示为纯文本.格式化文本的唯一帮助.为了向用户显示HTML,您需要转义所有特殊字符.

Simply using <xmp> or <pre> tag won't help you display HTML as plain text. The just help to format the text. In order to show HTML to your users you need to escape all special characters.

例如,将所有<符号替换为&lt;,并将所有>符号替换为&gt;.

For example, replace all < signs with &lt; and all > signs with &gt;.

我只显示了两个符号,谷歌快速搜索将帮助您找到所有符号及其替代物.

I've shown just two symbols, a quick google search will help you to find all the symbols and their replacements.

如果您使用的是PHP,则它内置了执行此操作的功能.即htmlentities($str).搜索您正在使用的任何语言.

And in case you're using PHP, it has built in function to do this. i.e. htmlentities($str). Search for whatever language you are using.

请注意,< xmp>标签已弃用.

Note that <xmp> Tag has been deprecated.

这篇关于&lt; xmp&gt;的任何替代形式标记以将html呈现为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆