Character encoding php mysql

2019-01-28 22:29发布

I have a table where the data are stored like boîtes with none utf8 characters. Now I have my php script which works fine on my local machine.

$utf = utf8_decode($details);
echo "UTF8-DE : ".$utf."<hr>";-> `boîtes`

When I put this script on another machine its not working its echoing boîtes . I am sure it depends on the charset of the php or server? Any help please

2条回答
甜甜的少女心
2楼-- · 2019-01-28 22:49

Try set_charset function

For mySqli

mysqli_set_charset($connection, "utf8");

For mySql

mysql_set_charset("UTF8", $connection);

Alternative

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_unicode_ci'");
查看更多
别忘想泡老子
3楼-- · 2019-01-28 23:03

Set it up with headers

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

查看更多
登录 后发表回答