Solved

Foreign Characters Not Showing with PHP/MySQL

Posted on 2011-03-06
4
611 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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 dynamically set the form action using jQuery.

695 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