1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Preventing issues with special characters and page encoding issues
When different components exchange data with one another, issues can arise with the character encoding used for text.
For example, if the coding scheme used for the HTML page is UTF8 whereas the database uses Latin-1, accents will not be properly interpreted by MySQL. If pages contain special characters (text in Arabic or Chinese, accents) then such characters may display correctly on your site, but not in phpMyAdmin or vice versa...
In order to ensure that everything works correctly, you MUST specify the charset used in all places (UTF8 for the sake of simplicity)...
Use a text editor that is able to save your files in UTF8. If you import text files containing SQL, these must be edited with an editor that saves in UTF8.
Force your site's headers to UTF8 using the following PHP function:
header('Content-Type: text/html; charset=utf-8');
Add this to your HTML meta tags:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
Declare your databases and tables use UTF8 encoding in PHPMyAdmin (e.g. utf8_general_ci)
Add the following lines to the .htaccess file within your /web folder:
php_value default_charset utf-8
php_value mbstring.internal_encoding UTF-8
Add the PHP function mysql_set_charset created by mysql_connect in order to specify the encoding used for this connection (if you do not specify an encoding, the default value for this parameter may vary from server to server):
]$connection = mysql_connect($server, $username, $password);
mysql_set_charset('utf8', $connection);
You may also change the default setting across your entire hosting space by following the instructions in this documentation.
Once a MySQL connection has been established from a PHP script, you may also specify the UTF8 charset via the following commands:
mysql_query("SET NAMES 'utf8';");
mysql_query("SET CHARACTER SET 'utf8';");
If you recover a MySQL dump (backup) and you import it to your database, it may be that all accents are replaced by strange characters ("?" for example).
MySQL database backups are made in UTF8 format. The accented characters are then coded on two octets. Importing these backups poses no problem on our servers, but it is up to you to adapt your custom configuration for locally importing UTF8 bases on your post.
For example, you can carry out a latin1 utf8 conversion -> latin1 of the SQL file before importing.
If not, when importing from the database, you just have to specify that your entry file is in iso-latin1 format (import section, "file character sets") and the import will run without problems.
When the special characters are changed to a '?',the file you are importing is probably in non-UTF8 format and the software is probably configured to import a UTF-8 file. Linux can perform the conversion to UTF-8 with the command 'iconv'.