How to properly save non english character into MySQL database using PHP?

谁说我不能喝 提交于 2019-12-11 19:39:06

问题


I am working on parsing a HTML of website and saving information to database but in the website, there are Non English character (like Chinese, Indian, Korean, etc) that should be saved into MySQL. My problem is that in MySQL (when i view those information using PHP MyAdmin), it displays weird characters.

İlginç Gerçekler
ê³µì—°ì •ë³´ PARTI(ì—°ê·¹,콘서트,뮤지컬,오í...
ì •ì‹ ì—°ë ¹ 테스트

How to properly save these information to database?


回答1:


try using

mysql_query("SET NAMES 'UTF8'");

after mysql_connect or mysql_select_db. I use that for Turkish mysql_query("SET NAMES 'latin5'");




回答2:


First of all make sure that the Table and Row Encoding is UTF-8 Formated. Next you should save the PHP Script file as UTF-8 Encoded With or Without BOM.

Or you can try using htmlspecialchars(); function to do that.




回答3:


You must convert your insertion and/or tables to another coding style. Here you are how: http://dev.mysql.com/doc/refman/5.0/en/charset-convert.html




回答4:


change your table collation to utf8

$con=mysql_connect("hostname","username","password");

mysql_query("SET CHARACTER SET utf8",$con);

check also this post



来源:https://stackoverflow.com/questions/11345892/how-to-properly-save-non-english-character-into-mysql-database-using-php

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