开发者

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 "&ntilde" 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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜