Warning:preg_match() [function.preg-match]:Compilation failed:nothing to repeat解決方案

來源:互聯網
上載者:User
Warning:preg_match() [function.preg-match]:Compilation failed:nothing to repeat
Warning:preg_match() [function.preg-match]:Compilation failed:nothing to repeat at offset 0 in E:\EasyPHP-5.3.4.0\www\01\note_check.php on line 9 怎麼修改,望各高手幫幫我啊?
程式如下:
error_reporting(E_ALL ^ E_NOTICE);
require("global.php");
if($_POST){
if (is_file("./filterwords.txt")){//判斷給定檔案名稱是否為一個正常的檔案
$filter_word = file("./filterwords.txt");//把整個檔案讀入一個數組中
$str=$_POST['content'];
for($i=0;$i if(preg_match("/".trim($filter_word[$i])."/i",$str)){//應用Regex,判斷傳遞的留言資訊中是否含有敏感詞
echo "";
exit;
}
}
}
$content =$_POST['content'];
$user_name = $_POST['user_name'];
$title = $_POST['title'];
$mood= $_GET['mood'];
$head = $_POST['head'].".gif";
$note_flag=$_POST['checkbox'];
if($note_flag!=1){$note_flag=0;}
$datetime=date("Y-m-d H:i:s");
$sql = "insert into tb_note (note_user,note_title,note_content,note_mood,note_time,note_user_pic,note_flag) values('".$user_name."','".$title."','".$content."','".$mood."','".$datetime."','".$head."','".$note_flag."')";
$DB->query($sql);
$url = "./index.php";
redirect_once($url);
}
?>

------解決方案--------------------
你的 $filter_word[$i] 中包含了 perl 保留字,尤其是 ?、+、*
需要轉義
正確的寫法是
preg_match("/".preg_quote(trim($filter_word[$i]))."/i",$str)
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.