src/Pinyin.php
protected function prepare($string, $option = \PINYIN_DEFAULT)
    {
        $string = preg_replace_callback('~[a-z0-9_-]+~i', function ($matches) {
            return "\t".$matches[0];
        }, $string);

        $regex = array('\p{Han}', '\p{Z}', '\p{M}', "\t");

        if ($this->hasOption($option, \PINYIN_KEEP_NUMBER)) {
            \array_push($regex, '\p{N}');
        }

        if ($this->hasOption($option, \PINYIN_KEEP_ENGLISH)) {
            \array_push($regex, 'a-zA-Z');
        }

        if ($this->hasOption($option, \PINYIN_KEEP_PUNCTUATION)) {
            $punctuations = array_merge($this->punctuations, array("\t" => ' ', '  ' => ' '));
            $string = trim(str_replace(array_keys($punctuations), $punctuations, $string));

            \array_push($regex, preg_quote(implode(array_merge(array_keys($this->punctuations), $this->punctuations)), '~'));
        }

        return preg_replace(\sprintf('~[^%s]~u', implode($regex)), '', $string);
    }
protected function prepare($string, $option = \PINYIN_DEFAULT)
    {
        $string = preg_replace_callback('~[a-z0-9_-]+~i', function ($matches) {
            return "\t".$matches[0];
        }, $string);

        $regex = array('\p{Han}', '\p{Z}', '\p{M}', "\t");

        if ($this->hasOption($option, \PINYIN_KEEP_NUMBER)) {
            \array_push($regex, '\p{N}');
        }

        if ($this->hasOption($option, \PINYIN_KEEP_ENGLISH)) {
            \array_push($regex, 'a-zA-Z');
        }

        if ($this->hasOption($option, \PINYIN_KEEP_PUNCTUATION)) {
            $punctuations = array_merge($this->punctuations, array("\t" => ' ', '  ' => ' '));
            $string = trim(str_replace(array_keys($punctuations), $punctuations, $string));

            \array_push($regex, preg_quote(implode(array_merge(array_keys($this->punctuations), $this->punctuations)), '~'));
        }

        return preg_replace(\sprintf('~[^%s]~u', implode($regex)), '', $string);
    }
protected function prepare ( $ string , $ option = \ PINYIN_DEFAULT ) { $ string = preg_replace_callback ( '~[a-z0-9_-]+~i' , function ( $ matches ) { return "\t" . $ matches [ 0 ] ; } , $ string ) ; $ regex = array ( '\p{Han}' , '\p{Z}' , '\p{M}' , "\t" ) ; if ( $ this -> hasOption ( $ option , \ PINYIN_KEEP_NUMBER ) ) { \ array_push ( $ regex , '\p{N}' ) ; } if ( $ this -> hasOption ( $ option , \ PINYIN_KEEP_ENGLISH ) ) { \ array_push ( $ regex , 'a-zA-Z' ) ; } if ( $ this -> hasOption ( $ option , \ PINYIN_KEEP_PUNCTUATION ) ) { $ punctuations = array_merge ( $ this -> punctuations , array ( "\t" => ' ' , '  ' => ' ' ) ) ; $ string = trim ( str_replace ( array_keys ( $ punctuations ) , $ punctuations , $ string ) ) ; \ array_push ( $ regex , preg_quote ( implode ( array_merge ( array_keys ( $ this -> punctuations ) , $ this -> punctuations ) ) , '~' ) ) ; } return preg_replace ( \ sprintf ( '~[^%s]~u' , implode ( $ regex ) ) , '' , $ string ) ; }
Pre-process.

@param string $string
@param int    $option

@return string
Pre - process .