开发者

Zend Framework escaping utf8 encoded characters

I am currently pulling in feed data in another languages. I do the following and store into mysql.

$content = htmlentities($item->title, ENT_COMPAT, "UTF-8");

when I output the text, using $this-开发者_高级运维>escape it still escapes the encoded entity.

So I get : á instead of á

Any idea?


Don't do htmlentities, do htmlspecialchars, htmlentities encodes many things that need not or even should not be encoded:

$content = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8');

If the feed data is not encoded in utf-8, you may need to convert it, before htmlspecialchars:

$content = mb_convert_encoding($item->title, 'UTF-8', '<encoding of the other side>');

Note that "encoding of the other side" may prove important.

By the way, if you are going to output it as HTML without any filtering, consider storing it as native HTML.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜