Home >Backend Development >PHP Tutorial > htmlentities() 单双引号不转换解决办法

htmlentities() 单双引号不转换解决办法

WBOY
WBOYOriginal
2016-06-13 13:47:151253browse

htmlentities() 单双引号不转换

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $str = "John & 'Adams'";
echo htmlentities($str, ENT_COMPAT);
echo "<br />";
echo htmlentities($str, ENT_QUOTES);
echo "<br>";
echo htmlentities($str, ENT_NOQUOTES);
?>



如下是我截图,为什么对单双引号不转换??

如下是我浏览器输出

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
John & 'Adams'<br>John & 'Adams'<br>John & 'Adams'





------解决方案--------------------
那么那些&打头的是什么?
------解决方案--------------------
?ENT_COMPAT - 默认。仅编码双引号。
?ENT_QUOTES - 编码双引号和单引号。
?ENT_NOQUOTES - 不编码任何引号。
------解决方案--------------------
' 就是单引号
------解决方案--------------------
估计楼主看的是HTML在浏览器中显示出来的效果,而不是看的HTML源码
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn