Last active
May 24, 2019 01:15
-
-
Save rundnovic/c67bf82699861d20acab3aee554698f7 to your computer and use it in GitHub Desktop.
递归过滤标点符号
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<php | |
public function getFilterStr($str) | |
{ | |
//$str = "环境优雅,干净卫生,,,,服务态。。。。度亲切,性价比高,涉外宾馆,值得推荐??????"; | |
$filteredStr = $this->filterSign($str); | |
return $filteredStr; | |
} | |
protected function filterSign($str) | |
{ | |
$punctuationArr = [ | |
"!", "!", | |
"?", "?", | |
"~", "~", | |
"。", ".", | |
":", ":", | |
",", "," | |
]; | |
foreach ($punctuationArr as $sign) { | |
if (strpos($str, $sign . $sign) !== false) { | |
$str = str_replace($sign . $sign, $sign, $str); | |
$str = $this->filterSign($str); | |
} | |
} | |
return $str; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment