แปลง utf-8 เป็น tis-620 ด้วย PHP
ฟังก์ชั่นแปลง UTF-8 เป็น tis-620 ในฐานข้อมูล เก็บข้อมูลแบบ tis-620 พอจะเอาข้อความจาก Google ซึ่งเป็น UTF-8 เพื่อนำมาค้นหาคำในฐานข้อมูล ปรากฏว่า ไม่เจอ เพราะ อ่านกันไม่รู้เรื่อง ดังนั้น ต้องแปลง ให้เป็น tis-620 ก่อนที่จะนำไปค้น ฟังก์ชั่นที่ได้แปลง ต่อไปนี้ ได้มาจาก http://www.howforge.com/convert-utf-8-to-tis-620-in-php 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; } ตัวอย่างการใช้งาน $subject = utf8_to_tis620(($_GET["subject"])); // รับข้อมูลเข้ามา แล้วแปลงเป็น tis-620