I’m having a little trouble getting character encodings to work for one of my applications. I have a large directory of names, many of which are foreign. My goal is to get as many of these names to render as possible. I’ve decided to use a utf-8 encoding to get this to work.
I’ve had to do a lot of work and testing to figure out everywhere that I need to change this encoding but I think i’m close. There seems to be just 1-2 places left that could be causing the problem.
An example of the problem. The word Zürich renders as Zürich.
In order to get the names into the database I imported them using a csv file. I use a mysql database.
These are the places i’ve made changes/checked to ensure that the character encoding is UTF-8.
Original .csv file is UTF-8
Database is UTF-8
Database table encodings are UTF-8
Webpage Doctype is UTF-8.
Putty SSH Client - UTF-8 encoding.
I’ve viewed the data directly in the mysql database and it renders correctly as Zürich. However, when it is displayed on the website it displays as Zürich. This leads me to believe that there is something in the process between the database and the webpage that is messign up the data (because both the database and webpage our UTF-8 encodings). I’ve also tried statically displaying Zürich on the webpage and it displays fine so it must be something else.
Do I need to control the encoding in the SQL query on the database? Can you think of anything else that might be causing this problem to occur?
For reference: here is the doctype of the webpage displaying the data.
<!DOCTYPE html
PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
<title>title</title>
<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8” />
I really appreciate your help. This has become quite a frustrating mess.
Edit: I’ve narrowed it down more.
As previously mentioned, the character encoding appears to be correct in the database when viewing through putty.
I created a simple sql command to grab the data from the database. Then ran these two lines of code.
$result = $db->query($sql);
$row = $result->fetch_assoc();
print_r($row);
print “Zürich”;
The display I get is:
Zürich
Zürich
So the problem is isolated to the database query. Suggestions on what I need to do to fix this?