开发者

How to correct output of special characters that is stored in mysql

开发者 https://www.devze.com 2023-03-05 03:55 出处:网络
How do I handle the output correctly because I have characters like these é , á , ú, ýbut...when I query it shows this character �

How do I handle the output correctly because I have characters like these é , á , ú, ý but...when I query it shows this character �

I already did my homework( research)

I fix the meta tag

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

and added mysql_query("SET NAMES 'utf8'"); after the mysql connection.

can anyone suggest solutions? ,开发者_开发技巧 please thank you

--edit--

Im just creating a basic SELECT query using PHP and MySQL

I set already the Collation to 'utf8_general_ci' for the column Im querying


Check your table encoding and client side encoding. Are these all the same?


Running SET NAMES after the data is garbled wont make much of a difference. I recently had the same problem. I fixed it with the following steps

  1. Loaded up all the content into a UTF8 page with a form in it. (This is without SET NAMES)
  2. Added SET NAMES to the connection
  3. Posted back all the data and saved it as UTF8

When you load the page the first time without SET NAMES it should show up properly. If it's not showing properly in the form, that means you might have forgotten to set the encoding on your page.

This is assuming that all your tables have the proper collation/encoding.


Are you 100% sure the collation is set properly for all tables in your database? You could try out a tool like Phoca Changing Collation to convert your whole database to utf8_general_ci.

This could corrupt your current data so be sure to make a proper backup before you run it.


Try putting this line at the top of your PHP file:

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

精彩评论

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

关注公众号