Data-id= "1190000005008217" data-license= "sa" >
1. htmlspecialchars($string, $flag)
(convert special characters to HTML entities converting special characters to HTML entities)
预定义的字符是:& (和号)成为 &" (双引号)成为 "' (单引号)成为 '< (小于)成为 <> (大于)成为 >
$flag defaults toENT_COMPAT | ENT_HTML401
constant Name |
Description |
Ent_compat |
Convert double quotes without converting single quotes. |
Ent_quotes |
Both single and double quotation marks are converted. |
Ent_noquotes |
Both single and double quotation marks are not converted. |
ent_html401 |
Processed as HTML 4.01 encoding. |
Ent_xml1 |
Processed as XML 1 encoding. |
Ent_xhtml |
Processed as XHTML encoding. |
Ent_html5 |
Processed as HTML 5 encoding. |
Exp:
$str = '"2015竞赛&"'; echo htmlspecialchars($str); //"2015竞赛&"quot;
2. htmlspecialchars_decode($string, $flag)
(in contrast to the above, convert special HTML entities back to normal characters)
Exp
$str = "this -> "
\n" ; echo htmlspecial_decode($str); // this -> " /*不转换双引号*/ echo htmlspecial_decode($str, ENT_NOQUOTES); // this -> "
3. Htmlentities
`htmlentities($string, $flag)`这个函数与htmlspecialchars的区别网上教程说是也会转换中文,但是我本地php5.5测试两个效果一样
$str='测试页面'; echo htmlentities($str); $str='测试页面'; echo htmlspecialchars($str);
4. Html_entity_decode
是`htmlentities`的反函数
5.nl2br
转换换行符(\n(unix), \r(Mac), \r\n(Win))为`
`
The above describes the PHP special character conversion entity function summary, including special characters, PHP content, I hope the PHP tutorial interested in a friend helpful.