Example #1
0
 function getWordRule($word, $lastchar = 1)
 {
     $rule = $word;
     $val = utf8_to_unicode($word);
     $len = sizeof($val);
     #print $word.':'.$len;
     if ($len >= 1) {
         // make a regex using with the last char
         $ch = array_pop($val);
         if ($ch >= 0xac00 and $ch <= 0xd7a3 or $ch >= 0x3130 and $ch <= 0x318f) {
             $jamo = hangul_to_jamo(array($ch));
             $wlen = sizeof($jamo);
             if ($wlen >= 3) {
                 if (in_array($jamo[2], array(0x11ab, 0x11af, 0x11b7, 0x11b8, 0x11bb))) {
                     $rule = unicode_to_utf8($val);
                     if ($lastchar == 1) {
                         $rule .= unicode_to_utf8(jamo_to_syllable(array($jamo[0], $jamo[1])));
                     } else {
                         $rule .= unicode_to_utf8(array(hangul_choseong_to_cjamo($jamo[0])));
                         $rule .= unicode_to_utf8(array(hangul_jungseong_to_cjamo($jamo[1])));
                     }
                     $rule .= unicode_to_utf8(array(hangul_jongseong_to_cjamo($jamo[2])));
                 }
             }
         }
     }
     return $rule;
 }
Example #2
0
function hangul_jamo_to_cjamo($jamo)
{
    if ($jamo >= 0x1100 && $jamo <= 0x1112) {
        return hangul_choseong_to_cjamo($jamo);
    }
    if ($jamo >= 0x1161 && $jamo <= 0x1175) {
        return hangul_jungseong_to_cjamo($jamo);
    }
    if ($jamo >= 0x11a7 && $jamo <= 0x11c2) {
        return hangul_jongseong_to_cjamo($jamo);
    }
    // else
    return $jamo;
}