第一步:composer require “overtrue/laravel-pinyin:~3.0”
第二步:配置
1,Add the following line to the section providers of config/app.php:在配置文件config/app.php配置一下參數
‘providers’ => [
//…
Overtrue\LaravelPinyin\ServiceProvider::class,
],
2,as optional, you can use facade:你也可以使用別名
‘aliases’ => [
//…
‘Pinyin’ => Overtrue\LaravelPinyin\Facades\Pinyin::class,
],
/**
- 拼音的擴展包使用
*/
public function testOfPinyin(){
$pinyin = new Pinyin();
$name = “我是小白”;
$name_spell = name);
$name_initial = name);
name_spell));//轉爲字符串,並且轉爲大寫 XIAZHAOJIANTANGPEI
name_initial);//轉爲大寫 XZJTP
echo name_spell;
exit();
}