<?php
function GetUtf8String($str) {
$arr_cho = array("¤¡", "¤¢", "¤¤", "¤§", "¤¨", "¤©", "¤±","¤²", "¤³", "¤µ", "¤¶", "¤·", "¤¸", "¤¹","¤º", "¤»", "¤¼", "¤½", "¤¾");
$arr_jung = array("¤¿", "¤À", "¤Á", "¤Â", "¤Ã", "¤Ä", "¤Å","¤Æ", "¤Ç", "¤È", "¤É", "¤Ê", "¤Ë", "¤Ì","¤Í", "¤Î", "¤Ï", "¤Ð", "¤Ñ", "¤Ò", "¤Ó");
$arr_jong = array("", "¤¡", "¤¢", "¤£", "¤¤", "¤¥", "¤¦","¤§", "¤©", "¤ª", "¤«", "¤¬", "¤", "¤®","¤¯", "¤°", "¤±", "¤²", "¤´", "¤µ", "¤¶","¤·", "¤¸", "¤º", "¤»", "¤¼", "¤½", "¤¾");
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i=0, $loop=strlen($str);$i<$loop;$i++) {
$thisValue = ord($str[$i]);
if ($thisValue < 128) {
$unicode[] = $thisValue;
} else {
if (count($values) == 0) $lookingFor = $thisValue < 224 ? 2 : 3;
$values[] = $thisValue;
if (count($values) == $lookingFor) {
$number = $lookingFor == 3 ? (($values[0]%16)*4096)+(($values[1]%64)*64)+($values[2]%64) : (($values[0]%32)*64)+($values[1]%64);
$unicode[] = $number;
$values = array();
$lookingFor = 1;
}
}
}
$splitStr = '';
while (list($key,$code) = each($unicode)) {
if ($code >= 44032 && $code <= 55203) {
$temp = $code-44032;
$cho = (int)($temp/21/28);
$jung = (int)(($temp%(21*28)/28));
$jong = (int)($temp%28);
$splitStr.= $arr_cho[$cho].$arr_jung[$jung].$arr_jong[$jong];
} else {
$temp = array($unicode[$key]);
foreach ($temp as $ununicode) {
if ($ununicode < 128) {
$splitStr.= chr($ununicode);
} elseif ($ununicode < 2048) {
$splitStr.= chr(192+(($ununicode-($ununicode%64))/64));
$splitStr.= chr(128+($ununicode%64));
} else {
$splitStr.= chr(224+(($ununicode-($ununicode%4096))/4096));
$splitStr.= chr(128+((($ununicode%4096)-($ununicode%64))/64));
$splitStr.= chr(128+($ununicode%64));
}
}
}
}
$splitStr = str_replace(' ','',$splitStr);
return $splitStr;
}
// UTF-8 ¹®ÀÚ¿ »ý¼º
$str = iconv('euc-kr','utf-8','¾ËÂê\'s ¿ÜºÎ±â¾ïÀåÄ¡');
echo GetUtf8String($str);
// return ¤·¤¿¤©¤¹¤Ñ's¤·¤Ê¤²¤Ì¤¡¤Ó¤·¤Ã¤¡ ¤¸¤¿¤·¤º¤Ó
?>
|
|