Re: Character encoding

From: Date: Wed, 05 Aug 2009 15:44:02 +0000
Subject: Re: Character encoding
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-296332@lists.php.net to get a copy of this message
On 08/05/2009 07:05 AM, Sándor Tamás (HostWare Kft.) wrote:
Hi, I have a mysql database, which the users can insert comments. As the users can be from different countries, with different character encoding, the mysql table can contain various special characters. How can I be sure to display these comments properly? I've found the mb_convert_encoding, and for some characters it works okay, but there are some really special characters which displayed as a '?'. Does anybody know some workarounds? Thanks, SanTa
Use UTF-8. Create your database and its tables with UTF-8 char encoding. eg. ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci Note there's no hyphen. Also, make sure the *data* is converted. You can use iconv for that. Next, ensure that the browser knows how to display the text. Use either a header or a meta tag (or both): <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> This is especially important for the page with the comments form. Any SQL file with your data (for import) should have the following at the top: SET NAMES 'utf8'; If you export a dump make sure that line is present before trying to import.

« previous php.general (#296332) next »