tp5 汉字转拼音、获取汉字首字母的方法

发布于 2019-12-24 09:17:21

首先通过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);
0 条评论

发布
问题