【发布时间】:2014-08-20 21:50:37
【问题描述】:
error:preg_match_all(): Compilation failed: nothing to repeat at offset 59
大家好,我正在尝试为客户制作一个单词过滤器,我遇到了我的代码女巫从文本文件中提取单词的问题,无法从我的文本文件中读取 $ 字符,mycode 在下面。
$lines=array();
$fp=fopen('/opt/lampp/htdocs/Comments/Classes/Bad.txt', 'r');
while (!feof($fp))
{
$line=fgets($fp);
//process line however you like
$line=trim($line);
//add to array
$lines[] = preg_quote(trim($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>";
}
【问题讨论】:
标签: php regex pattern-matching preg-match preg-match-all