嘿,我正在为一个学校项目制作一个单词传感器,我似乎无法让preg_match过滤掉字符,如$,%,*,1-9和其他我试过的特殊字符w,\ W,[W] +但以下似乎都不起作用
$lines=array();
$fp=fopen('Bad.txt', 'r');
while (!feof($fp))
{
$line=fgets($fp);
//process line however you like
$line=trim($line);
//add to array
$lines[]=$line;
}
fclose($fp);
$string = Input::get('comments');
$matches = array();
$matchFound = preg_match_all(
"/\b(" . implode($lines,"|") . ")\b/i",
$string,
$matches
);
if ($matchFound) {
$this->addError("The following is not allowed please change it.");
$words = array_unique($matches[0]);
foreach($words as $word) {
echo "<li>" . $word . "</li>";
}
echo "</ul>";
}