Convert UTF-8 to TIS-620 in PHP
In case you don’t have iconv and mbstring, you might use below function to convert UTF-8 to TIS-620.
function utf8_to_tis620($string) {
$str = $string;
$res = "";
for ($i = 0; $i < strlen($str); $i++) {
if (ord($str[$i]) == 224) {
$unicode = ord($str[$i+2]) & 0x3F;
$unicode |= (ord($str[$i+1]) & 0x3F) << 6;
$unicode |= (ord($str[$i]) & 0x0F) << 12;
$res .= chr($unicode-0x0E00+0xA0);
$i += 2;
} else {
$res .= $str[$i];
}
}
return $res;
}
Read more at Convert TIS-620 to UTF-8 in PHP.
Technorati Tags: English, Programming, PHP, Tips and Tricks, UTF-8, Utf8, TIS-620, Tis620
- sugree's blog
- 6901 reads
พี่คับช่ว
Great!
Post new comment