首先通过composer安装类库:
composer require "overtrue/pinyin:~4.0"
使用:
$pinyin = new \Overtrue\Pinyin\Pinyin(); $str = "你好"; $py = $pinyin->convert($str); // ['ni', 'hao'] dump($py); $first = $pinyin->abbr($str,','); // 'n,h' dump($first);
发布 问题
回到 顶部