如何将文本放入 html 中看起来像标签的 p 标签中 [英] How to put text in a p tag in html that looks like a tag

查看:45
本文介绍了如何将文本放入 html 中看起来像标签的 p 标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把文本放在 html 的 p 标签中.但是,当代码运行时,文本被读取为标签,而不仅仅是文本.如何让计算机将其作为文本阅读.

I want to put the text in a p tag in html. However, when the code runs, the text is read as a tag, instead of just text. How do I get the computer to just read this as text.

<p class="body-copy-mini space"> 
    Change <name> tag's value 'Your App name' to whatever your app name is. <br>
                        Change <description> tag's value <br>
                        Change <author> tag's values <br>
                    </p>

推荐答案

这是因为 HTML 会将 ‘<’ 视为开始标记并尝试呈现它.例如,您需要将所有适用的字符转换为其 HTML 实体以防止这种情况发生要显示‘<’,您需要将其转换为‘&lt;’,而对于‘>’,您需要将其转换为‘>’.还有一些其他字符需要编码,一些语言为此内置了函数,例如在 PHP 中,您可以使用htmlentities()"函数.

It’s because HTML will treat ‘<‘ as opening tag and will try to render it. You need to convert all the applicable characters to their HTML entities to prevent this, for example For showing ‘<‘ you need to convert it to ‘&lt;’ and for ‘>’ you need to convert it to ‘&gt;’. There are some other characters which you will need to encode, some languages have built in function for this, example in PHP you can use ‘htmlentities()’ function.

试试这个

<p class="body-copy-mini space"> 
Change &lt;name&gt; tag's value 'Your App name' to whatever your app name is. <br>
                    Change &lt;description&gt; tag's value <br>
                    Change &lt;author&gt; tag's values <br>
                </p>

工作示例

这篇关于如何将文本放入 html 中看起来像标签的 p 标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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