Jump to content
Squarepusher

Unicode characters displayed incorrectly

Recommended Posts

No matter what I try, unicode characters that are read from a MySQL database like japanese ones are replaced by "?" while characters like "ä", "ö", "ü", "»", "«", etc. are replaced by "�".

I pasted this at the top of the PHP code:

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

mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_regex_encoding('UTF-8');

I saved the PHP file as UTF-8 and UTF-8 without BOM and put <meta charset="UTF-8"> into it. (When I insert unicode characters directly in the file, they're displayed correctly, though...)

I set the encoding in the phpMyAdmin database table to different "UTF-8" encodings. (They're displayed correctly too when viewed in the table directly...)

Nothing worked so far.

 

Any ideas?

Edited by Squarepusher

Share this post


Link to post
Share on other sites

Perhaps your database connection code needs to be set to use UTF-8.

Share this post


Link to post
Share on other sites

I set "collation connection", "collation server" and "collation database" to "utf8_general_ci" and "character set server", "character set results", "character set filesystem", "character set database", "character set connection" and "character set client" to "utf8" but it still doesn't help.

Share this post


Link to post
Share on other sites

You need to change the actual connection, between your PHP script and MySQL.  You do that in your PHP code.  e.g.:

$pdo = new PDO(    
        "mysql:host=localhost;dbname=databasename",     
        "user",    
        "pass",     
        array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×