Skip to content

Instantly share code, notes, and snippets.

@rundnovic
Last active May 24, 2019 01:15
Show Gist options
  • Save rundnovic/c67bf82699861d20acab3aee554698f7 to your computer and use it in GitHub Desktop.
Save rundnovic/c67bf82699861d20acab3aee554698f7 to your computer and use it in GitHub Desktop.
递归过滤标点符号
<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