Unicode Like Chinese Japanese Korean Characters In and Out MySQL Through PHP
Both MySQL and PHP support the Unicode, namely UTF-8. To be able to store into and retrieve these Unicode characters in MySQL database, one would need to do following things:
MySQL needs to be informed through PHP. So, following code need to be placed just after the connection. If the connection is centralized, this code is better to be in that centralized file:
mysql_query("SET NAMES 'UTF8'");
For all your PHP files generates HTML codes, please include following code at top of the file:
header("Content-Type: text/html; charset=UTF-8");
For all your HTML files, following code is needed in the head of HTML:
‹ meta http-equiv="Content-Type" content="text/html; charset=UTF-8" ›
Done. Please note, in first piece of PHP code, it is UTF8 and in second PHP code and last HTML code it is UTF-8. Else, it won’t work properly.
Both MySQL and PHP support the Unicode, namely UTF-8. To be able to store into and retrieve these Unicode characters in MySQL database, one would need to do following things:
MySQL needs to be informed through PHP. So, following code need to be placed just after the connection. If the connection is centralized, this code is better to be in that centralized file:
mysql_query("SET NAMES 'UTF8'");
For all your PHP files generates HTML codes, please include following code at top of the file:
header("Content-Type: text/html; charset=UTF-8");
For all your HTML files, following code is needed in the head of HTML:
‹ meta http-equiv="Content-Type" content="text/html; charset=UTF-8" ›
Done. Please note, in first piece of PHP code, it is UTF8 and in second PHP code and last HTML code it is UTF-8. Else, it won’t work properly.