Unicode (UTF-8) with PHP 5.3, MySQL 5.5 and HTML5 Cheat Sheet

  • Published on
    28-Nov-2014

  • View
    2.714

  • Download
    0

Embed Size (px)

DESCRIPTION

An overview of the most important things to know when working with PHP, MySQL and Unicode.

Transcript

Unicode (UTF-8) with PHP 5.3, MySQL 5.5 and HTML5 Cheat SheetCONVERSIONHow to transform file encodingExample with PHP files on Linux:find . -name "*.php" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o /path/to/utf8_files/{} \;

CONFIGURATIONHTTP and HTMLIn php.ini [1]:default_charset = UTF-8

MYSQL CODEMySQLRight after each connection, call1 [2]:SET NAMES 'utf8';

Stored Procedures and FunctionsOld function:CREATE FUNCTION example_function ( IN parameter_name VARCHAR(255) RETURNS varchar(255) READS SQL DATA BEGIN DECLARE data VARCHAR(255); ... RETURN data; END;

or in httpd.conf or .htaccess [5]:AddDefaultCharset UTF-8

Ordering in MySQLOrdering in MySQL depends on the collation you choose. Detailed information about this subject may be found in the documentation on MySQL.com [2]. Look especially at the Unicode Character Sets section: http://dev.mysql.com/doc/refman/5.5/en/charsetunicode-sets.html.

or in the PHP code [5]:header('Content-type: text/html; charset=UTF-8');

Additionally, put this in you HTML block: