Difference between revisions of "UTF-8 Compatible"
Line 22: | Line 22: | ||
{{red | '''''<nowiki>USE <dbname>;</nowiki>'''''}} | {{red | '''''<nowiki>USE <dbname>;</nowiki>'''''}} | ||
=== Telling MySQL to query in UTF-8 mode === | === Telling MySQL to query in UTF-8 mode === | ||
+ | after connecting to the database and before quering the DB for data we need to let mysql know that we want the data to be returned in utf format by sending the following query: | ||
+ | |||
+ | ''mysql_query("SET NAMES utf8");'' | ||
+ | |||
=== Letting PHP know that you are working with UTF-8 === | === Letting PHP know that you are working with UTF-8 === | ||
Edit /etc/php.ini and insert the following line<br> | Edit /etc/php.ini and insert the following line<br> | ||
{{red|<nowiki>default_charset = "utf-8</nowiki>"}} | {{red|<nowiki>default_charset = "utf-8</nowiki>"}} |
Revision as of 11:47, 8 February 2007
Converting WebPages to UFT-8
grconv -T UTF -t iso-8859-7 iso_filename > utf_filename Alternatively you can use the iconv command which is available on most systems iconv -f iso-8859-7 -t utf-8 iso_filename > utf_filename
The next three-line script will search for all your html and php files and convert them to utf-8
!!! WARNING !!!: The following script is provided as is. USE AT YOUR OWN RISK!!!
I am not responsible for data or life loss by using it. nsc
find . \( -name "*.htm*" -o -name "*.php" \) -exec sed -i.iso 's/charset\=iso\-8859\-7/utf\-8/g' '{}' \; for i in `find . \( -name "*.htm*" -o -name "*.php" \)` ; do iconv -f iso-8859-7 -t utf-8 $i.iso > $i; done find . \( -name "*.htm*" -o -name "*.php" \) -exec sed -i 's/charset\=iso\-8859\-7/utf\-8/g' '{}' \;
NOTE: The above lines are only an example of how you can convert your site to be utf compatible. The second line is only working if you are in bash shell
Converting MySQL databases to UTF-8
Dump the db in an SQL file.
mysqldump -u root -p --lock-tables --default-character-set=greek dbname > dbname.sql
Edit the SQL file and insert the following two lines at the beginning of it.
CREATE DATABASE <dbname> DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE <dbname>;
Telling MySQL to query in UTF-8 mode
after connecting to the database and before quering the DB for data we need to let mysql know that we want the data to be returned in utf format by sending the following query:
mysql_query("SET NAMES utf8");
Letting PHP know that you are working with UTF-8
Edit /etc/php.ini and insert the following line
default_charset = "utf-8"