Skip to content

Instantly share code, notes, and snippets.

@lex0000
Last active August 29, 2015 14:12
Show Gist options
  • Save lex0000/61e68b6b5c298b8d2502 to your computer and use it in GitHub Desktop.
Save lex0000/61e68b6b5c298b8d2502 to your computer and use it in GitHub Desktop.
function thai($x) {
$back = array(
"\xE0\xB9\x88" => "\xEF\x9C\x85", //่(ไม้เอก)=>
"\xE0\xB9\x89" => "\xEF\x9C\x86", //้(ไม้โทร)=>
"\xE0\xB9\x8A" => "\xEF\x9C\x87", //๊(ไม้ตรี)=>
"\xE0\xB9\x8B" => "\xEF\x9C\x88", //+(ไม้จัตวา)=>
"\xE0\xB9\x8C" => "\xEF\x9C\x89" //์(ตัวการัน)=>
);
$cross = array();
$payanchana=array(
"\xE0\xB8\xB4", //สระอิ
"\xE0\xB8\xB5", //สระอี
"\xE0\xB8\xB6", //สระอึ
"\xE0\xB8\xB7", //สระอือ
"\xE0\xB8\xB1", //ไม้หันอากาศ
"ำ" //สระอำ \xE0\xB8\xB3
);
//http://www.endmemo.com/unicode/thai.php อ้างอิง unicode
foreach ($payanchana as $p) {
if($p!='ำ'){
for ($i = 0x85; $i <= 0x89; $i ++) {
$from = $p . "\xEF\x9C" . chr($i);
$to = $p . "\xE0\xB9" . chr($i +3);
$cross[$from] = $to;
}
}else{
for ($i = 0x85; $i <= 0x89; $i ++) {
$from = "\xEF\x9C" . chr($i).$p;
$to = "\xE0\xB9" . chr($i +3).$p;
$cross[$from] = $to;
}
}
}
$x = strtr($x, $back);
$x = strtr($x, $cross);
return $x;
}
@lex0000
Copy link
Author

lex0000 commented Dec 26, 2014

mpdf แก้สระลอย จากบทความนี้ https://gist.github.com/dtinth/716814/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment