Xpressengine\Tag\Decomposer::execute PHP Method

execute() public method

Execute decomposing
public execute ( string $string ) : string
$string string string whatever
return string
    public function execute($string)
    {
        $cho = ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
        $jung = ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
        $jong = ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", " ㅌ", "ㅍ", "ㅎ"];
        $result = "";
        for ($i = 0; $i < $this->strlen($string); $i++) {
            $char = $this->charAt($string, $i);
            $code = $this->ord($char) - 44032;
            if ($code > -1 && $code < 11172) {
                $choIdx = $code / 588;
                $jungIdx = $code % 588 / 28;
                $jongIdx = $code % 28;
                $result .= $cho[$choIdx] . $jung[$jungIdx] . $jong[$jongIdx];
            } else {
                $result .= $char;
            }
        }
        return $result;
    }

Usage Example

Ejemplo n.º 1
0
 public function testExecute()
 {
     $instance = new Decomposer();
     $this->assertEquals('ㄱㅏㄴㅏㄷㅏ', $instance->execute('가나다'));
     $this->assertEquals('ㄱㅏabㄴㅏcㄷㅏde', $instance->execute('가ab나c다de'));
     $this->assertEquals('aㄱㅏㄴㅏ bcㄷㅏ de', $instance->execute('a가나 bc다 de'));
 }
All Usage Examples Of Xpressengine\Tag\Decomposer::execute