UTF-8 Compatible

From CSWiki
Jump to navigation Jump to search

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.

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.

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");

If you are using the url-way for connecting to the DB then use the following format:

$dsn = mysql://<username>:<password>@<dbserver>/<dbname>?charset=utf8

Letting PHP know that you are working with UTF-8

Edit /etc/php.ini and insert the following line
default_charset = "utf-8"