开发者

utf8_encode and accented characters dilemma?

I am facing a paradox in decoding with utf8_encode decode. I have a MySQL database with uft8 collation and whose fields have the utf8_general coding. I have my php file in utf8, and in my HTML pages I have specified in the header the utf8 charset.

My problem is that when I select from my table a field containing accented characters (like èçò ùé) and echo that to the browser, I get strange characters.

To resolve my problem, I have to echo $description=utf8_encode($imm['description']).

My question is why can’t I do the echo directly 开发者_开发知识库without having to use uft8_encode every time?


I'll just guess that your database connection is not set to UTF-8.
See SET NAMES utf8 in MySQL?


you need to specify the header using php to be utf-8. also make sure that the format of the chars is utf-8 before storing in the db because utf_encode encodes an ISO-8859-1 string to UTF-8, which most likely means that the chars are being stored as ISO-8859-1 in s a utf-8 table.

make sure that you convert those chars in utf-8 before storing them in the db and then echo should not be a problem at all.

Source: had the exact same problem myself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜