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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...