Created
November 26, 2010 14:59
-
-
Save dtinth/716814 to your computer and use it in GitHub Desktop.
Utility function to fix floating tone marks when outputting as PDF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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(); | |
foreach (array("\xE0\xB8\xB4", "\xE0\xB8\xB5", "\xE0\xB8\xB6", "\xE0\xB8\xB7") as $p) { | |
for ($i = 0x85; $i <= 0x89; $i ++) { | |
$from = $p . "\xEF\x9C" . chr($i); | |
$to = $p . "\xE0\xB9" . chr($i + 3); | |
$cross[$from] = $to; | |
} | |
} | |
$x = strtr($x, $back); | |
$x = strtr($x, $cross); | |
return $x; | |
} |
ปรับให้วรรณยุกต์ที่ซ้อนอยู่บน อิ อี อึ อือ และไม้หันอากาศ อยู่ชิดขวาของตัวอักษร ให้เป็นธรรมชาติมากขึ้น
function thai($x)
{
$back = array(
"\xE0\xB9\x88" => "\xEF\x9C\x8A", // ไม้เอก
"\xE0\xB9\x89" => "\xEF\x9C\x8B", // ไม้โท
"\xE0\xB9\x8A" => "\xEF\x9C\x8C", // ไม้ตรี
"\xE0\xB9\x8B" => "\xEF\x9C\x8D", // ไม้จัตวา
"\xE0\xB9\x8C" => "\xEF\x9C\x8E" // ตัวการันต์
);
$cross = array();
$vowels = 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 ($vowels as $p) {
if ($p != 'ำ') {
for ($i = 0x8A; $i <= 0x8E; $i++) {
$from = $p . "\xEF\x9C" . chr($i);
$to = $p . "\xE0\xB9" . chr($i - 2);
$cross[$from] = $to;
}
} else {
for ($i = 0x8A; $i <= 0x8E; $i++) {
$from = "\xEF\x9C" . chr($i) . $p;
$to = "\xE0\xB9" . chr($i - 2) . $p;
$cross[$from] = $to;
}
}
}
$x = strtr($x, $back);
$x = strtr($x, $cross);
return $x;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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) {
}