Foreign Characters Not Showing with PHP/MySQL

European characters are not displaying properly:
1. the characters are correct in the MySQL table
2. Field collation is set to utf8_general_ci
3. PHP page contains
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Have tried inserting into the PHP:
1. mysql_query("SET NAMES utf8");
2. mysql_query("SET CHARACTER SET utf8");
3. mysql_query("SET CHARACTER_SET_RESULTS=NULL");

Can get the characters to show on the local server with line 3 inserted; but not when uploaded to the remote server. Can see no explaining differences on the phpinfo page.

Tearing hair out.
smudgemouseAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Bernard S.Connect With a Mentor CTOCommented:
Problem with these character displays is that there are several layers of potential problems.

1 - When looking at you data with phpmyadmin, do the characters display normally or not? (use phpmyadmin in UTF 8 then in your local char code)
While  you are displaying your data in both displays, also try to input accented characters as well. Does it work?

If one of them does, then you have one beginning of track / solution: you know for sure that somehow the accented characters can be placed in MySQL and displayed.
Now is the time to write down on paper what you know:
- for each mode, what happens when you input accented characters? how do they display
(you really need paper as a tracking tool, 'cause these are really confusing if you just keep them in your mind)
- for your pages, can you display or not these characters? in fact get the date with usual mysql function, THEN display it in 3 flavors: normal, utf8_encode, utf8_decode
update your paper!
- what is the char code of the html PAGE (ie, the charset you define in the html code)? it should be UTF8 of course... but check; test the impact of using your browser to display in other code (display / code), and if any change... write down on your paper...
- what is the char code of the php FILE and of any included file: are they all utf8? if no... test on one or 2 what happens when you convert the file to utf8. NOTE: beware you must use utf8 WITHOUT BOM, otherwise strange things will happen
(I personally use Ultra-Edit from IdmComp to handle this, and I would strongly recommend it, since most other solutions are somehow doing incorrect conversions // Ultra-Edit is a commercial product, but you can run a time-limited free trial version)

2 - If none of this works, then you have to explore the server / Apache track
0
 
rruschCommented:
Have you checked Apache config? I had to add "AddDefaultCharset UTF-8" to httpd.conf.
0
 
smudgemouseAuthor Commented:
"...and of any included file: are they all utf8..."

Let us to look at a Connection file in an include. Used Set Names etc and it works.

Thank you very much
0
 
Bernard S.CTOCommented:
B-) Glad we could help. Thx for the grade and points.

These char code problems are really a nightmare!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.