htmlspecialchars() 函数把预定义的字符转换为 HTML 实体。
预定义的字符是:
& (和号)成为 &
" (双引号)成为 "
' (单引号)成为 '
< (小于)成为 <
echo htmlspecialchars($str);
会被解码的 HTML 实体是:
& 解码成 & (和号)
" 解码成 " (双引号)
' 解码成 ' (单引号)
< 解码成 < (小于)
echo htmlspecialchars_decode($str);
htmlspecialchars_decode详情:http://www.w3school.com.cn/php/func_string_htmlspecialchars_decode.asp
预定义的字符是:
& (和号)成为 &
" (双引号)成为 "
' (单引号)成为 '
< (小于)成为 <
> (大于)成为 >
栗子:
$str = "This is some <b>bold</b> text.";echo htmlspecialchars($str);
htmlspecialchars输出:This is some <b>bold</b> text.
会被解码的 HTML 实体是:
& 解码成 & (和号)
" 解码成 " (双引号)
' 解码成 ' (单引号)
< 解码成 < (小于)
> 解码成 > (大于)
栗子:
$str = "This is some <b>bold</b> text.";echo htmlspecialchars_decode($str);
htmlspecialchars_decode输出:This is some bold text.
htmlspecialchars_decode详情:http://www.w3school.com.cn/php/func_string_htmlspecialchars_decode.asp