Skip to content

Instantly share code, notes, and snippets.

@aimakun
Forked from anonymous/gist:4674232
Last active December 11, 2015 23:08
Show Gist options
  • Save aimakun/4674243 to your computer and use it in GitHub Desktop.
Save aimakun/4674243 to your computer and use it in GitHub Desktop.
Convert tis620 to utf8 text function (for legacy database).
<?php
function tis620_to_utf8($text) {
$utf8 = "";
for ($i = 0; $i < strlen($text); $i++) {
$a = substr($text, $i, 1);
$val = ord($a);
if ($val < 0x80) {
$utf8 .= $a;
} elseif ((0xA1 <= $val && $val < 0xDA) || (0xDF <= $val && $val <= 0xFB)) {
$unicode = 0x0E00+$val-0xA0; $utf8 .= chr(0xE0 | ($unicode >> 12));
$utf8 .= chr(0x80 | (($unicode >> 6) & 0x3F));
$utf8 .= chr(0x80 | ($unicode & 0x3F));
}
}
return $utf8;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment