阅读背景:

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
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   怎么修改,望各高手帮帮我啊?
程序如下:
<?php
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<count($filter_word);$i++){ //应用For循环语句对敏感词进行判断
    if(preg_match("/".trim($filter_word[$i])."/i",$str)){ //应用正则表达式,判断传递的留言信息中是否含有敏感词
  echo "<script> alert('留言信息中包含敏感词!');history.back(-1);</script>";
  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);
}
?>

4 个解决方案

#1


你的 $filter_word[$i] 中包含了 perl 保留字,尤其是 ?、+、*
需要转义
正确的写法是
preg_match("/". preg_quote(trim($filter_word[$i]) )."/i",$str)

#2


(唠叨) 
谢谢您了

#3


多谢了,果然有用@!

#4


该回复于2012-04-11 15:30:13被版主删除

\note_check.php on line 9   怎么修改,望各高手帮帮我啊? Warning:preg_match() [function.preg-match]:Comp



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: