Overtrue\Pinyin\Pinyin::convertSurname PHP Method

convertSurname() protected method

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