function utf8_to_tis620
This function converts the string from utf8 to tis620. For example, the webpage use encoding utf-8 but table charset is tis620. So i must convert strings to tis620-strings before saving by using this custom function or built-in function to your discretion. At my experience, i have use built-in function for Thai language conversion but possess a flaw on some figures. Therefore i change to refer to this custom function instead.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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; } |
function tis620_to_utf8
This function converts the string of tis620 to utf8, such as data stored in the table is tis620 but when display on page it as utf8 (as is standard encoding on webpage today).
Through this post html to pdf with php ที่รองรับภาษาไทย, using this custom function for conversion data.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function tis620_to_utf8($in) { $out = ""; for ($i = 0; $i < strlen($in); $i++) { if (ord($in[$i]) $out .= $in[$i]; else $out .= "" . (ord($in[$i]) - 161 + 3585) . ";"; } return $out; } |
php convert utf-8 to tis-620 and tis-620 to utf-8