PHP禁止在preg_match上使用单词过滤器错误

时间:2014-09-03 04:15:19

标签: php preg-match

我在使用此代码时遇到了一些问题。它返回:警告:preg_match()[function.preg-match]:未知的修饰符'\'

另外,我想知道如何在提交时将此代码称为表单上的php包含文件,以便在将数据插入数据库之前对提交的textarea运行检查。我知道这完全是一个单独的问题,我最终可能会发布它。也许只是基本概念作为回答,指出我正确的方向。

if (isset($_POST['text'])) {

// Banned Words
$disallowedWords = array(
'badword'
);

// Find Banned Words

foreach ($disallowedWords as $word) {
if (preg_match("/\s+$word\s+/i", $entry)) {
die("The word '$word' is not allowed...");
}
}

// Match URLs

$urlRegex = '(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0
-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-
9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}
|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-
Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.
(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-
9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*';

// Search for URLs
if (preg_match($urlRegex, $entry)) {
die("URLs are not allowed...");
}

} 


<form name="startpost" action="" method="post">
<textarea rows="8" cols="90" name="text" rows="4" maxlength="300"></textarea>
<input type="submit" name="submit" id="submit" value="Send post" />
</form>

0 个答案:

没有答案