* fix for pinyin class in php5.2

This commit is contained in:
wangyidong
2018-09-02 09:02:53 +08:00
parent 85e93fa29d
commit fa5f0518bf
+13 -11
View File
@@ -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];
}
}