如何将 html 代码添加到网站但不将其实际转换为代码?

发布于 2024-11-16 15:13:05 字数 156 浏览 1 评论 0原文

我不知道如何描述这个。基本上我想在我的网站中显示我的网站的编码。。所以我不确定要贴什么标签。我已经做了一些谷歌搜索,但我什至不确定我在谷歌搜索什么。我找到了这些标签,但似乎没有一个起作用。我发现脚本标签不是我需要的,而代码标签却没有达到我想要的效果。有人知道该怎么办吗? 提前致谢

I'm not sure how to describe this one. Basicly I want to show the coding of my website, in my website. So I'm not sure what tag to put. I've done some googling but i'm not even sure what I'm Googleing. I've found these tags, but none of them seemed to work. I found the script tag which I found out isn't what I needed and the code tag but that didn't do what I wanted. Anyone know what to do?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

2024-11-23 15:13:05

< 写为 < 并将 > 写为 > (它们的字符实体等价物)。这将防止浏览器将它们解释为标签。

因此,不要

<p>This is an <i>example</i> of html.<p>

<p>This is an <i>example</i> of html.</p>

“乏味,但必要”。从技术上讲,> 仅当其前面有 < 某处时才被视为标记结束符,因此您可能能够只需执行 < -> 就可以了<,但以实体格式写出这两个字符更安全。

完成后,您可能需要使用

 标记(如预格式化)将其包裹起来,这将导致间距和换行符的呈现方式与源代码中的显示方式相同。

write the < as < and the > as > (their character entity equivalents). This will prevent the browser from interpreting them as tags.

So instead of

<p>This is an <i>example</i> of html.<p>

You'd write

<p>This is an <i>example</i> of html.</p>

Tedious, but necessary. Technically speaking, a > is only seen as a tag closer if it was preceded by a < somewhere, so you MIGHT be able to get by with just doing < -> <, but it's safer to write out both characters in entity format.

Once that's done you may want to wrap it with the <pre> tag (as in preformatted) which will cause the spacing and line breaks to be rendered just as they appear in your source code.

顾忌 2024-11-23 15:13:05

对每个适用的符号使用 HTML 实体。或者,您可以使用 PHP 并通过 htmlentities 运行字符串。

Utilize the HTML entity for each applicable symbol. Alternatively, you could use PHP and run the string through htmlentities.

忆伤 2024-11-23 15:13:05

我不确定你是否可以用一个简单的标签来做到这一点,但我使用这个 php 库将我的代码转换为漂亮的 html 代码
http://qbnz.com/highlighter/

I am not sure if you can do it with a simple tag, but I use this php library to convert my code to nice html code
http://qbnz.com/highlighter/

墨落画卷 2024-11-23 15:13:05

看看这个,我想这可能就是您正在寻找的。
http://code.google.com/p/google-code-prettify/

take a look at this, i think it may be what you are looking for.
http://code.google.com/p/google-code-prettify/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文