Translate website from TIS-620 to UTF-8

Posted: กันยายน 3, 2014 in ไม่มีหมวดหมู่

Translate database

ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
SHOW TABLES;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

Translate php file by shell script

#!/bin/bash
FROM=TIS-620
TO=UTF-8
ICONV="iconv -f $FROM -t $TO//IGNORE"

find /var/www/website -type f -name "*.php" | while read fn; do
 cp ${fn} ${fn}.bak
 $ICONV < ${fn}.bak > ${fn}
 rm ${fn}.bak
done

find and replace in Terminal

find /var/www/website -type f -name "*.php" -exec sed -i 's/TIS-620/UTF-8/g' {} \; 
find /var/www/website -type f -name "*.php" -exec sed -i 's/TIS620/UTF8/g' {} \;
find /var/www/website -type f -name "*.php" -exec sed -i 's/windows-874/UTF-8/g' {} \;

use mb_ in php string function

first setup default in php.ini

mb_internal_encoding = "UTF-8"
find /var/www/website -type f -name "*.php" -exec sed -i 's/strlen/mb_strlen/g' {} \;
find /var/www/website -type f -name "*.php" -exec sed -i 's/strpos/mb_strpos/g' {} \;
find /var/www/website -type f -name "*.php" -exec sed -i 's/substr/mb_substr/g' {} \;
find /var/www/website -type f -name "*.php" -exec sed -i 's/strtolower/mb_strtolower/g' {} \;
find /var/www/website -type f -name "*.php" -exec sed -i 's/ereg/mb_ereg/g' {} \;

Reference:

http://stackoverflow.com/questions/6115612/how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8
https://github.com/EllisLab/CodeIgniter/issues/261
http://www.thaiseoboard.com/index.php/topic,315829.0.html

Advertisements

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s