Skip to content

Instantly share code, notes, and snippets.

@lex0000
Forked from dtinth/thai.php
Created February 21, 2019 11:05
Show Gist options
  • Save lex0000/44f8dbd744408a53e30e88b04a35ebf3 to your computer and use it in GitHub Desktop.
Save lex0000/44f8dbd744408a53e30e88b04a35ebf3 to your computer and use it in GitHub Desktop.
Utility function to fix floating tone marks when outputting as PDF.
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment