Convert TIS-620 to UTF-8 in PHP
In case you don’t have iconv and mbstring, you might use below function to convert TIS-620 to UTF-8.
function tis620_to_utf8($text) {
$utf8 = "";
for ($i = 0; $i < strlen($text); $i++) {
$a = substr($text, $i, 1);
$val = ord($a);
if ($val < 0x80) {
$utf8 .= $a;
} elseif ((0xA1 <= $val && $val < 0xDA) || (0xDF <= $val && $val <= 0xFB)) {
$unicode = 0x0E00+$val-0xA0;
$utf8 .= chr(0xE0 | ($unicode >> 12));
$utf8 .= chr(0x80 | (($unicode >> 6) & 0x3F));
$utf8 .= chr(0x80 | ($unicode & 0x3F));
}
}
return $utf8;
}
Read more at Convert UTF-8 to TIS-620 in PHP.
Technorati Tags: English, Programming, PHP, Tips and Tricks, UTF-8, Utf8, TIS-620, Tis620
- sugree's blog
- 4277 reads
Post new comment