Forum Moderators: coopster
I've enabled UT8 in the MySQL config, PHP config and Apache config.
I can view the UT8 characters correctly in phpMyAdmin. The data is stored correctly in the MySQL db.
However, when I call the data on a PHP page, PHP displays a? instead of the characters from the db.
I've enabled UTf8 in the php.ini
default_charset = "utf-8"
I've also called the header in the PHP page with the UTF8:
header('content-type: text/html; charset: utf-8');
Is there something that I've missed? What do I need to do to get my PHP pages to display the character set correctly?
Note: phpMyAdmin displays UTF8 correctly from the db.
Thanks
I had the same trouble. Try this
<!-- xml version="1.0" encoding="UTF-8" -->
<!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">
<head></head>
<body>
<?php echo $utf8variable;?>
<body>
<html>
You know that the page is in utf-8, so my guess is that you are double utf-8 encoding somewhere. Sounds strange, but I seem to recall having done this myself somewhere. Besides the two things you outlined in your first message, is there anything else you are trying in the process to get these characters to utf-8?
I've listed below the contents of my AMP config files. These are the only config areas where I've enabled UTF8.
php.ini contents
default_charset = "utf-8"
my.cnf contents
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
default-character-set=utf8
default-collation=utf8_unicode_ci
character-set-client = utf8
httpd.conf contents
AddDefaultCharset UTF-8
and the php script itself has this in the first line:
header('content-type: text/html; charset: utf-8');
TIA
You are correct. The first line is APOLONIA and second is SIFNOS (greek).
This issue did not occur between databases. I imported the characters correctly into MySQL and have not been able to read them from my PHP scripts since.
This forum encoded the Greek characters that I pasted earlier.
How did you insert the characters into your db? Did you insert the string that I pasted? In my db, the names are inserted in the non-encoded format. That is, APOLONIA and SIFNOS in greek.
Were you able to store the non-encoded names into the db and then read them correctly through your PHP script? If so, I would appreciate if you could share your PHP script.
Thank You
So you may try to add a:
[mysqld]
init-connect='SET NAMES utf8'
to set this as a default for all connections, or start with these queries after your specific script connects to the database before sending other queries:
SET NAMES utf8;
SET CHARACTER_SET utf8;
Kind regards,
R.
Adding the init-connect did not work.
I am pasting below the output for show variables. Maybe there is something there I may have missed.
mysql> show variables like 'c%';
+--------------------------+-------------------------------------------------------------------+
¦ Variable_name ¦ Value ¦
+--------------------------+-------------------------------------------------------------------+
¦ character_set_client ¦ utf8 ¦
¦ character_set_connection ¦ utf8 ¦
¦ character_set_database ¦ utf8 ¦
¦ character_set_filesystem ¦ binary ¦
¦ character_set_results ¦ utf8 ¦
¦ character_set_server ¦ utf8 ¦
¦ character_set_system ¦ utf8 ¦
¦ character_sets_dir ¦ /usr/local/mysql-standard-5.0.27-linux-i686/share/mysql/charsets/ ¦
¦ collation_connection ¦ utf8_general_ci ¦
¦ collation_database ¦ utf8_unicode_ci ¦
¦ collation_server ¦ utf8_unicode_ci ¦
¦ completion_type ¦ 0 ¦
¦ concurrent_insert ¦ 1 ¦
¦ connect_timeout ¦ 5 ¦
+--------------------------+-------------------------------------------------------------------+
TIA
I was able to read the UTF8 characters correctly from the db!
What happened was, I was calling an includes file that contains the database connect info. The includes file connected to multiple databases, some latin and some UTF8.
I removed the includes file and tested by just calling the UTF8 database. The data displayed correctly.
How do I get UTF8 to work with the includes file? Is there a way to specify the UTF8 in the mysql_connect or mysql_select_db function? I guess that would selectively force UTF8 on the database that uses it?
TIA
I've listed two records from the table. These are greek characters.ΑΠΟΛΩΝΊΑk
ΣΊΦΝΟΣ
Is that what you see in phpmyadmin in the textbox/area for that data? If so, Ive seen this before but cannot recall exactly what we did to sort it out.
We had a mysql db storing Cyrillic characters as entities, as you do, but you want mysql to store the utf-8 characters. What we did here was to work over the DB so that it stored the actual utf-8 characters, not the entities.
I'll have to poke around but I remember using some functions that I found on php.net, including utf8dec, uft8html2utf8 and some others.