special characters to html entity using php
I want to convert special characters like ñ, Ñ to htmlentities using php.
I tried using htmlentities, but开发者_StackOverflow中文版 instead of returning "ñ" for its value it returns "ñ" as its value.
Make sure that your page charset is set to utf-8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
You need to specify the character set you use as the third parameter to htmlentities(). The default character set is iso-8859-1
. If you use UTF-8 for your data, you need to say so:
$result = htmlentities($string, ENT_QUOTES, "UTF-8");
You have to specify the charset because the default is ASCII (http://php.net/manual/en/function.htmlentities.php):
htmlentities($stringToConvert, ENT_COMPAT, 'UTF-8')
精彩评论