Overtrue\Pinyin\Pinyin::sentence PHP Method

sentence() public method

Chinese to pinyin sentense.
public sentence ( string $sentence, $withTone = false ) : string
$sentence string
return string
    public function sentence($sentence, $withTone = false)
    {
        $marks = array_keys($this->punctuations);
        $punctuationsRegex = preg_quote(implode(array_merge($marks, $this->punctuations)), '/');
        $regex = '/[^üāēīōūǖáéíóúǘǎěǐǒǔǚàèìòùǜa-z0-9' . $punctuationsRegex . '\\s_]+/iu';
        $pinyin = preg_replace($regex, '', $this->romanize($sentence));
        $punctuations = array_merge($this->punctuations, array("\t" => ' ', '  ' => ' '));
        $pinyin = trim(str_replace(array_keys($punctuations), $punctuations, $pinyin));
        return $withTone ? $pinyin : $this->format($pinyin, false);
    }