When characters of the wrong encoding are read to the browser, they come up as � or ?. There is an encoding mismatch somewhere:
- In your browser
- In the database table collation
- In the HTML charset
Those characters would work in Unicode UTF-8, so you should verify that your DB table collation is utf8_bin
or similar, as, if you want to store everything in UTF-8 Swedish, you might use utf8_swedish_ci
In your browser, ensure that your content encoding is set to auto-detect.
To create a UTF-8 / utf8_bin table in MySQL, here is an example:
CREATE TABLE `sample` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
To ALTER an existing table to use UTF-8, use the following command:
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
This post has a good explanation of whether or not to use CONVERT TO CHRACTER SET utf8
Note CHARSET
and COLLATE
must both be set, otherwise you will automatically get COLLATE=utf8_general_ci
For HTML, charset can be set using:
<meta charset="UTF-8">