• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP实现过滤留言信息中的敏感词

php 搞代码 4年前 (2022-01-22) 14次浏览 已收录 0个评论

PHP实现过滤留言信息中的敏感词

一 代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>检测留言信息的敏感词</title></head><body><table width="761" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FEFEFE" bgcolor="#FFFFFF">  <form action=""  method="post" name="form1" id="form1">    <tr>      <td width="761" align="center" bgcolor="#F9F8EF"><table width="749" border="0" align="center" cellpadding="0"  cellspacing="0"  style="BORDER-COLLAPSE: collapse">        <tr>          <td height="36" colspan="3" align="left" " bgcolor="#F9F8EF" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓&nbsp;&nbsp;名:            <input  name="user_name" id="user_name" value=" 匿名" maxlength="64" type="text" />              <span             style="COLOR: #ff0000">*</span></td>        </tr>        <tr>          <td height="36" colspan="3" align="left"  bgcolor="#F9F8EF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;标&nbsp;&nbsp;题:            <input maxlength="64" size="30" name="title"  type="text"/>              <span style="COLOR: #ff0000">*</span></td>        </tr>        <tr>          <td height="126" colspan="3" align="left"  bgcolor="#F9F8EF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;内&nbsp;&nbsp;容:            <textarea name="content" cols="60" rows="8" id="content" ></textarea>              <span style="COLOR: #ff0000">*</span></td>        </tr>        <tr>          <td height="40" colspan="3" align="center"  bgcolor="#F9F<div>本文来*源gaodai^.ma#com搞#代!码网</div><pre>搞gaodaima代码

8EF"><input name="submit" type="submit" class="btn1" id="submit" value="签写留言"/>&nbsp;&nbsp;<input name="reset" type="reset" class="btn1" value="清除留言" /></td> </tr> </table></td> </tr> <tr> <td width="761" align="center" bgcolor="#F9F8EF"><table width="749" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="703" height="31" align="center" >&nbsp;</td> </tr> </table></td> </tr> </form></table></body></html><?phpif($_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;}}}}?>


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP实现过滤留言信息中的敏感词
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址