The function of both functions is to convert characters to HTML character encodings, especially URLs and code strings. Prevents character markers from being executed by the browser. There is no difference in the use of Chinese, but Htmlentities will format Chinese characters so that the input is garbled
Htmlentities Convert all HTML tags, htmlspecialchars only format & ' "< and > these special symbols
$str = ' <a href= ' demo.php?m=index&a=index&name= Chinese > test page </a> ';
Echo ' htmlentities specifies GB2312 encoding: '. Htmlentities ($str, Ent_compat, "GB2312"). ";
Echo ' htmlentities unspecified encoding: '. Htmlentities ($STR). ";
$str = ' <a href= ' demo.php?m=index&a=index&name= Chinese > test page </a> ';
echo Htmlspecialchars ($STR). ";
Effect:
Htmlentities Specify GB2312 encoding: <a href= "demo.php?m=index&a=index&name= Chinese" > test page </a>
Htmlentities encoding not specified: <a href= "Demo.php?m=index&a=index&name=öðîä" >²âÊÔÒ³Ãæ</a>
<a href= "demo.php?m=index&a=index&name= Chinese" > test page </a>
Source:
Htmlentities Specify GB2312 code: <a href="demo.php?m=index&a=index&name= Chinese "& gt; test page </a><br/>htmlentities code not specified: <a href="demo.php?m=index&a=index &name=ÖÐÎÄ">²âÊ& Ocirc;ò³ãæ</a><br/><a href=" Demo.php?m=index&a=index&name= Chinese "> test page </a><br/>
The difference between htmlentities and Htmlspecialchars in PHP