Created
October 9, 2015 16:51
-
-
Save Colorfulstan/86e030308712c5a1cdf3 to your computer and use it in GitHub Desktop.
From http://kkovacs.eu/how-not-to-mess-up-encodings How to ensure utf-8 encoded database / html / php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- and, for safety and consistency, also adding this to your html-head output: --> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//From your PHP code, set your MySQL connection up to use UTF-8 all the time (if not configured so by //default, but usually it is not). This means the following SQL right after connecting to the DB: | |
set character_set_results=utf8, character_set_client=utf8, character_set_connection=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Next, set the HTTP connection to use UTF-8. This means addig this code early on (your head.inc or //similar): | |
header('Content-Type: text/html; charset=utf-8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `table` ( | |
`ID` bigint(20) unsigned NOT NULL auto_increment, | |
`TEXT` longtext NOT NULL, | |
PRIMARY KEY (`ID`), | |
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment