* fix for pinyin class in php5.2
This commit is contained in:
+13
-11
@@ -43,17 +43,7 @@ class pinyin
|
||||
*/
|
||||
public function prepare($string)
|
||||
{
|
||||
if(version_compare(PHP_VERSION, '7.2.0') >= 0)
|
||||
{
|
||||
$string = preg_replace_callback('/[a-z0-9_-]+/i', function($matches)
|
||||
{
|
||||
return "\t" . $matches[0];
|
||||
}, $string);
|
||||
}
|
||||
else
|
||||
{
|
||||
$string = preg_replace_callback('/[a-z0-9_-]+/i', create_function('$matches', 'return "\t" . $matches[0];'), $string);
|
||||
}
|
||||
$string = preg_replace_callback('/[a-z0-9_-]+/i', array($this, 'prepareCallback'), $string);
|
||||
return preg_replace("/[^\p{Han}\p{P}\p{Z}\p{M}\p{N}\p{L}\t]/u", '', $string);
|
||||
}
|
||||
|
||||
@@ -71,4 +61,16 @@ class pinyin
|
||||
$string = strtr($string, $this->segments);
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The callback for prepare method.
|
||||
*
|
||||
* @param array $matches
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function prepareCallback($matches)
|
||||
{
|
||||
return "\t" . $matches[0];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user