$str = "just atest & 'learn to use '";
echo html_entity_decode($str);
echo "
";
echo html_entity_decode($str,ENT_QUOTES);
echo "
";
echo html_entity_decode($str,ENT_NOQUOTES);
输出如下:
just a test & 'learn to use '
just a test & 'learn to use '
just a test & 'learn to use '
$str = "just a test & 'learn to use'";
echo htmlentities($str,ENT_COMPAT);
echo "
";
echo htmlentities($str, ENT_QUOTES);
echo "
";
echo htmlentities($str, ENT_NOQUOTES);
输出如下:
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
查看源代码如下:
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
预定义字符包括:单引号(‘),双引号(“),反斜杠(),NULL
默认情况下,PHP指令 magic_quotes_gpc 为 on,对所有的GET、POST 和COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数get_magic_quotes_gpc() 进行检测。
$str3="\ just a ' \" test";
echo addslashes($str3);
输出:
\\ just a \' \" test
$str4="\\ just a \'\" test";
echo stripslashes($str4);
输出:
just a ' " test
预定义字符包括:& (和号) 成为&
" (双引号) 成为"
' (单引号) 成为'
< (小于) 成为<
> (大于) 成为>
$str5 = "just atest & 'learn to use'";
echo htmlspecialchars($str5, ENT_COMPAT);
echo "
";
echo htmlspecialchars($str5, ENT_QUOTES);
echo "
";
echo htmlspecialchars($str5, ENT_NOQUOTES);
输出:
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
查看源代码:
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
会被解码的html实体包括:& 成为 &(和号)
" 成为 " (双引号)
' 成为 ' (单引号)
< 成为 < (小于)
> 成为 > (大于)
$str6 = "just atest & 'learn to use'";
echo htmlspecialchars_decode($str6);
echo "
";
echo htmlspecialchars_decode($str6, ENT_QUOTES);
echo "
";
echo htmlspecialchars_decode($str6, ENT_NOQUOTES);
输出:
just a test & 'learn to use '
just a test & 'learn to use '
just a test & 'learn to use '
查看源代码:
just a test & 'learn to use '
just a test & 'learn to use '
just a test & 'learn to use '
$str= htmlspecialchars(addslashes($str));
$str= htmlspecialchars_decode(stripslashes($str));
声明:本文为转载文章,为防止丢失所以做此备份。
原文地址:https://www.jb51.net/article/99548.htm