src/Pinyin.php
protected function convertSurname($string, $dictLoader)
    {
        $dictLoader->mapSurname(function ($dictionary) use (&$string) {
            foreach ($dictionary as $surname => $pinyin) {
                if (0 === strpos($string, $surname)) {
                    $string = $pinyin.mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8');

                    break;
                }
            }
        });

        return $string;
    }
protected function convertSurname($string, $dictLoader)
    {
        $dictLoader->mapSurname(function ($dictionary) use (&$string) {
            foreach ($dictionary as $surname => $pinyin) {
                if (0 === strpos($string, $surname)) {
                    $string = $pinyin.mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8');

                    break;
                }
            }
        });

        return $string;
    }
protected function convertSurname ( $ string , $ dictLoader ) { $ dictLoader -> mapSurname ( function ( $ dictionary ) use ( & $ string ) { foreach ( $ dictionary as $ surname => $ pinyin ) { if ( 0 === strpos ( $ string , $ surname ) ) { $ string = $ pinyin . mb_substr ( $ string , mb_strlen ( $ surname , 'UTF-8' ) , mb_strlen ( $ string , 'UTF-8' ) - 1 , 'UTF-8' ) ; break ; } } } ) ; return $ string ; }
Convert Chinese Surname to pinyin.

@param string                               $string
@param \Overtrue\Pinyin\DictLoaderInterface $dictLoader

@return string
Convert Chinese Surname to pinyin .