PHP code example of fayland / php-lingua-unihan-pinyin

1. Go to this page and download the library: Download fayland/php-lingua-unihan-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/ */

    

fayland / php-lingua-unihan-pinyin example snippets


use Lingua\Unihan\PinYin;

echo Pinyin::pinyin('带着希望去旅行比到达终点更美好');
// dài zhe xī wàng qù lǔ xíng bǐ dào dá zhōng diǎn gèng měi hǎo

Pinyin::set('delimiter', '-');//全局
echo Pinyin::pinyin('带着希望去旅行比到达终点更美好');
// dài-zhe-xī-wàng-qù-lǔ-xíng-bǐ-dào-dá-zhōng-diǎn-gèng-měi-hǎo

Pinyin::set('tone', false);
echo Pinyin::pinyin('带着希望去旅行,比到达终点更美好');
// dai zhe xi wang qu lu xing bi dao da zhong dian geng mei hao