Created
January 30, 2013 15:58
-
-
Save anonymous/4674232 to your computer and use it in GitHub Desktop.
Convert tis-620 to utf-8 text function (for legacy data from database).
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 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