How to display Unicode data with PHP

execute query

SET NAMES 'utf8'

right after connecting to database


Try to set charachter encoding after mysql_connect function like this:

 mysql_query ("set character_set_client='utf8'"); 
 mysql_query ("set character_set_results='utf8'"); 

 mysql_query ("set collation_connection='utf8_general_ci'"); 

Try to make sure the browser recognizes the page as Unicode.

Generally, this can be done by having your server send the right Content-type HTTP header, that includes the charset you're using.


For instance, something like this should work :

header('Content-type: text/html; charset=UTF-8');
echo "வெள்ளிக்கிழமை ஐ";


If this works, and your dynamically generated page still doesn't :

  • make sure your data in your MySQL database is in UTF-8 too
    • this can be set for each table, or even columns, in MySQL
  • and make sure you are connecting to it using UTF-8.

Basically, all your application should use the same encoding :

  • PHP files,
  • Database
  • HTTP server

For new version of PHP which used mysqli, use this code after connect to mysql:

mysqli_set_charset($link, 'utf8');

Tags:

Mysql

Php

Unicode