PHP code example of overtrue / laravel-pinyin
1. Go to this page and download the library: Download overtrue/laravel-pinyin library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
overtrue / laravel-pinyin example snippets
'providers' => [
//...
Overtrue\LaravelPinyin\ServiceProvider::class,
],
'aliases' => [
//...
'Pinyin' => Overtrue\LaravelPinyin\Facades\Pinyin::class,
],
$pinyin = app('pinyin');
echo $pinyin->sentence('带着希望去旅行,比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo
var_dump(pinyin('带着希望去旅行,比到达终点更美好'));
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]
var_dump(pinyin_abbr('带着希望去旅行'));
// dzxwqlx
...
use Pinyin; // Facade class, NOT Overtrue\Pinyin\Pinyin
var_dump(Pinyin::convert('带着希望去旅行'));
// ["dai", "zhe", "xi", "wang", "qu", "lv", "xing"]
echo Pinyin::sentence('带着希望去旅行,比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng, bǐ dào dá zhōng diǎn gèng měi hǎo
use Overtrue\Pinyin\Pinyin;
// Memory Optimized (default) - ~400KB memory usage, suitable for web requests
Pinyin::useMemoryOptimized();
// Cached Strategy - ~4MB memory usage, 2-3x faster for repeated conversions
Pinyin::useCached();
// Smart Strategy - 600KB-1.5MB memory usage, adaptive loading
Pinyin::useSmart();
// Auto Strategy - automatically selects the best strategy for your environment
Pinyin::useAutoStrategy();
// Clear cache when needed (useful in long-running processes)
Pinyin::clearCache();