为什么filter_var()对引号的编码与htmlentities()不同?

时间:2019-04-10 07:20:32

标签: php encoding html-entities sanitization filter-var

为什么filter_var()的FILTER_SANITIZE_STRING过滤器将单引号编码为',将双引号编码为",而htmlentities()将单引号编码为',将双引号编码为{{1 }}?

代码示例:

"

输出:

<?php
$string = "Well that's \"different.\"";

echo "filter_var: ".filter_var($string, FILTER_SANITIZE_STRING)."\n";
echo "htmlentities: ".htmlentities($string, ENT_QUOTES)."\n";
echo "htmlspecialchars: ".htmlspecialchars($string, ENT_QUOTES)."\n";

0 个答案:

没有答案