Character encoding php mysql

喜欢而已 提交于 2019-11-28 09:25:04

问题


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


回答1:


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'");



回答2:


Set it up with headers

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



来源:https://stackoverflow.com/questions/18374009/character-encoding-php-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!