Difference between revisions of "UTF-8 Compatible"

From CSWiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
Alternatively you can use the iconv command which is available on most systems
 
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''
 
iconv -f iso-8859-7 -t utf-8 ''iso_filename'' > ''utf_filename''
 
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
 
  
 
The next three-line script  will search for all your html and php files and convert them to utf-8 <br>
 
The next three-line script  will search for all your html and php files and convert them to utf-8 <br>
Line 27: Line 24:
 
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:
 
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");''
+
''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 ===
 
=== 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>"}}

Latest revision as of 12:50, 31 October 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");

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"