Solved

Foreign Characters Not Showing with PHP/MySQL

Posted on 2011-03-06
4
580 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:smudgemouse
  • 2
4 Comments
 
LVL 2

Expert Comment

by:rrusch
ID: 35045885
Have you checked Apache config? I had to add "AddDefaultCharset UTF-8" to httpd.conf.
0
 
LVL 29

Accepted Solution

by:
fibo earned 500 total points
ID: 35046002
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
 

Author Closing Comment

by:smudgemouse
ID: 35046133
"...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
 
LVL 29

Expert Comment

by:fibo
ID: 35046653
B-) Glad we could help. Thx for the grade and points.

These char code problems are really a nightmare!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now