[英]PHP htmlentities Not Working
I am retrieving text and HTML tags from a database while using this function to encode the values for the browser. 我正在使用此功能编码浏览器的值时,从数据库中检索文本和HTML标记。
foreach ($row as $key => &$value){
$value = htmlspecialchars_decode(
htmlentities($value,ENT_QUOTES),
ENT_NOQUOTES
);
}
Basically, I am looping through each row and converting quotes, single quotes, and other special characters to entities while keeping HTML tags. 基本上,我遍历每一行,并将引号,单引号和其他特殊字符转换为实体,同时保留HTML标记。
However, when there's tags like <a href="example.com">
, the quotes are duplicated twice and outputs to this: 但是,当有类似
<a href="example.com">
的标签时,引号会重复两次并输出到此:
<a href=""example.com"">
. <a href=""example.com"">
。
What am I doing wrong? 我究竟做错了什么?
您应该使用htmlentities: htmlentities($str, ENT_QUOTES);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.