UFT-8 on a website based on mySQL and PHP
I spent quite some time today trying to get the text on a website with Bulgarian characters to show properly. The text is coming out of a MYSQL 5.0 database, configured to use utf8_general_ci and the website is generated by PHP 5.2.5.
I knew I had to use
meta equiv=”Content-Type” content=”text/html; charset=utf-8″
to display the Bulgarian characters properly (like Велико Търново) and that worked fine for static text, but I got ???????? when using the text from the database.
I tried all sorts of things, and visited various websites with proposed solution, but finally I got it working by one simple setting, explained by this website. I needed to include
mysql_query(‘SET NAMES utf8′);
when connecting to the database. That solved the issue.
This entry was posted on Sunday, March 2nd, 2008 at 13:26 and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
March 14th, 2008 at 11:02
Maike Utrera says:I had a simular issue using a webservice call that returned a XML file with SQL data. The only way to solve this was to set the charset to ISO 8859-1.
I hope this works you.
March 14th, 2008 at 11:38
Kris Gielen says:Maike,
) if you have to deal with Western European characters only. In my case, I needed Bulgarian characters (like добър прием) and they are not available in ISO 8859-1. So I was forced to stick with utf-8, but then you need to use the rather obscure “SET NAMES utf8″ setting in mysql. See http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html for details.
Thanks for your comments. That would indeed have been a simpler solution (once you know it
Kris
August 26th, 2008 at 23:35
Kris’s Box » Blog Archive » JavaScript uses url-encoded UTF-8 strings to perform Ajax POSTs says:[...] first thought it was an issue similar to the Bulgarian character set issue in mySQL I encountered a few months ago. But I was just using French in this case, so iso-8859-1 and mySQL [...]
May 27th, 2009 at 16:55
eD says:Usefull.
I also needed this headers to display bulgarian characters correctly from my DB:
header(‘Content-Type: text/html; charset=utf-8′);
mb_internal_encoding(“UTF-8″);
Bye!
April 22nd, 2010 at 05:55
Flavia Colamarino says:I usually do not leave comments, but I thought this was a great post! Kris’s Box » Blog Archive » UFT-8 on a website based on mySQL and PHP was a wonderful read. WoW:)