acidf0x / php-korean-handler
PHP韩文处理器 - 汉字分离器
v2.0.0
2022-01-22 10:35 UTC
Requires
- php: >=7.4
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2024-09-28 23:50:55 UTC
README
韩文假名分离库(初声,中声,终声)
安装
使用composer安装
composer require acidf0x/php-korean-handler
用法
查询时返回值是U+3130
到U+318F
之间的韩文兼容假名
use AcidF0x\KoreanHandler\Seperator; $separator = new Seperator(); $result = $separator->separate("수상하게 돈이 많은"); print_r($result->getSplitList()); // ["ㅅ","ㅜ","ㅅ","ㅏ","ㅇ","ㅎ","ㅏ","ㄱ","ㅔ","ㄷ","ㅗ","ㄴ","ㅇ","ㅣ","ㅁ","ㅏ","ㄶ","ㅇ","ㅡ","ㄴ"] print_r($result->getChoseongList()); // ["ㅅ", "ㅅ", "ㅎ", "ㄱ", "ㄷ", "ㅇ", "ㅁ", "ㅇ"] print_r($result->getJungseongList()); // ["ㅜ", "ㅏ", "ㅏ", "ㅔ", "ㅗ", "ㅣ", "ㅏ", "ㅡ"] print_r($result->getJongseongList()); // ["ㅇ","ㄴ","ㄶ","ㄴ"]
separate
方法返回值实现了ArrayAccess
、Iterator
接口,因此可以对每个结果像数组一样访问并使用
$result = $this->separator->separate("황소"); $result[0]->getChoseong(); // ㅎ $result[0]->getJungseong(); // ㅘ $result[0]->getJongseong(); // ㅇ $result[1]->getChoseong(); // ㅅ $result[1]->getJungseong(); // ㅗ $result[1]->getJongseong(); // null $result[0]->getSplit(); // ["ㅎ", "ㅘ", "ㅇ"] foreach ($result as $character) { $character->getChoseong(); }