Solved

Foreign Characters Not Showing with PHP/MySQL

Posted on 2011-03-06
4
603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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