Created
January 12, 2014 05:50
-
-
Save duyleekun/8381441 to your computer and use it in GitHub Desktop.
Get first sound of korean in PHP
This file contains hidden or 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 _uniord($c) { | |
if (ord($c{0}) >=0 && ord($c{0}) <= 127) | |
return ord($c{0}); | |
if (ord($c{0}) >= 192 && ord($c{0}) <= 223) | |
return (ord($c{0})-192)*64 + (ord($c{1})-128); | |
if (ord($c{0}) >= 224 && ord($c{0}) <= 239) | |
return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); | |
if (ord($c{0}) >= 240 && ord($c{0}) <= 247) | |
return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); | |
if (ord($c{0}) >= 248 && ord($c{0}) <= 251) | |
return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); | |
if (ord($c{0}) >= 252 && ord($c{0}) <= 253) | |
return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); | |
if (ord($c{0}) >= 254 && ord($c{0}) <= 255) // error | |
return FALSE; | |
return 0; | |
} | |
$INITIAL_SOUND = array('ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'); | |
$a = "각자음 마다 가지는 글자수"; | |
$firstChar = mb_substr($a,0,1,'utf8'); | |
var_dump($firstChar); | |
var_dump(_uniord($firstChar)); | |
$firstSoundOrd = floor((_uniord($firstChar) - 44032) / 588); | |
var_dump($firstSoundOrd); | |
$firstSound = $INITIAL_SOUND[$firstSoundOrd]; | |
var_dump($firstSound); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment