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

php中文网
发布: 2016-06-13 13:37:20
原创
2080人浏览过

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)){ //应用正则表达式,判断传递的留言信息中是否含有敏感词
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);
}
?>

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

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号