Solved

Foreign Characters Not Showing with PHP/MySQL

Posted on 2011-03-06
4
570 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
Comment Utility
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
Comment Utility
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
Comment Utility
"...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
Comment Utility
B-) Glad we could help. Thx for the grade and points.

These char code problems are really a nightmare!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Jquery Autocomplete PHP script 3 20
Page showing diff display 4 14
Not needed 13 53
Apostophes in PHP generated form 6 12
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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.

762 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

9 Experts available now in Live!

Get 1:1 Help Now