我是否应该将 ENT_QUOTES 与 htmlspecialchars 一起使用 [英] Should I use ENT_QUOTES with htmlspecialchars or not
问题描述
我正在使用以 UTF-8 运行的 php 5.4.4,我不确定我是否正确使用 htmlspecialchars.
I am using php 5.4.4 running as UTF-8, and im not sure if I am using htmlspecialchars right.
我的字符串/变量如下所示:
My strings / vars look like this:
$text = "<p><span class='clx'>By:</span> ".htmlspecialchars($foo)."</span></p>";
echo $text;
我是否需要使用 ENT_QUOTES
或者只有在我必须回显某些内容时才需要使用
Do I have need to use ENT_QUOTES
or is that only necessary when I have to echo something
内部例如:href="$foo" 或 id='$foo'
?
Atm, om 仅在封闭的 html 标签内使用 htmlspecialchars 而不是属性.
Atm, om only using htmlspecialchars inside closed html tags and not attributes.
只需将 <p>
标签和 </p>
标签内的字符串内的 var 连接起来
Just concatenate the var inside the string within a <p>
tag and a </p>
tag
谢谢
推荐答案
通常应该在从数据库中获取数据并将其插入到 html 元素中时使用它.这是为了使数据中的引号不会关闭值引号并弄乱 html.
You should generally use it when taking data from database and inserting it into html elements. This is so that quotes from the data don't close the value quotes and mess up the html.
这篇关于我是否应该将 ENT_QUOTES 与 htmlspecialchars 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!