开发者

Problems with utf8, php, and mysql

I'm fetching the JSON timeline from twitter and parsing it through PHP. I then want to store the text in my database.

The PHP script is in UTF8, I set the header to utf8 using this code, just in case:

header('Content-type: text/html; charset=UTF-8');

The table in the database uses utf8_general_ci, ...

Not even encoding the text using utf8_encode() works. I keep getting jumbled characters开发者_开发技巧, like 'autodestruição'

Does anyone know what I'm doing wrong?


You probably need to set your database connection to UTF-8 as well.

Try sending this query to the server after establishing the connection (and before INSERTing any data):

SET NAMES utf8;

If that doesn't work, please show the script you are using to fetch the data.


Use utf8_decode() or utf8_encode() method when delivering the JSON data.

Like

header('Content-type: text/html; charset=UTF-8');
echo utf8_decode($json_string);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜