Arabic text output php mysql utf-8 conversion issue

牧云@^-^@ 提交于 2019-12-03 21:23:44

问题


I'm importing data from Oracle database to MySQL tables.

I have set my MySQL table charset as utf8_general_ci and database and table name with field column value set as utf-8 as well.

Now, When I fetch the result, it prints like, which is with ? sign:

مرحبا العال� - 5

I have my utf value in column is مرحبا العالÙ

When I compare this string with Oracle string, it shows proper value - exact copy of Oracle database and there it shows perfect string in Arabic.

I have set my html meta with utf-8 as well

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >

If I set mysql query as below, it shows junk characters:

mysql_query("SET NAMES utf8;");
mysql_query("SET CHARACTER_SET utf8;");

Followed everything possible found over stack and other sites, and still getting an error.

Please help !


回答1:


Did you save the php-file without BOM? If not, try it. Potential issues with the UTF-8 BOM


Further try with 'utf-8' using single quotes and without SET CHARACTER_SET

mysql_query("SET NAMES 'utf8'");

and with charset utf-8 in the html-document header:

header("content-type: text/html; charset=utf-8");



回答2:


with pdo you should have this

$_dbhandler = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"));


来源:https://stackoverflow.com/questions/20731287/arabic-text-output-php-mysql-utf-8-conversion-issue

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