为什么我的正则表达式没有去掉句点?最终结果应该只输出字母和数字字符,加上'-',但我不断在输出中得到句点。我试过 trim($string, '.') 但没有用。请帮忙!
更新!我已经用正确的解决方案更新了代码。谢谢!
<?php
protected $trimCharacters = "/[^a-zA-Z0-9_-]/";
protected $validWords = "/[a-zA-Z0-9_-]+/";
private function cleanUpNoise($inputText){
$this->inputText = preg_replace($this->trimCharacters, '', $this->inputText);
$this->inputText = strtolower($this->inputText);
$this->inputText = preg_match_all($this->validWords, $this->inputText, $matches);
return $matches;
}
?>