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>
<link href="style/admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.STYLE1 { color: #FF0000;
 font-weight: bold;
}
.STYLE2 {color: #0033FF}
-->
</style>
</head>

<body>
<table width="98%" border="0" align="center" style="margin-top:20px; border:1px solid #9abcde;">
  <form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
    <tr >
      <td height="28" colspan="3" background="skins/top_bg.gif"><label> &nbsp;<strong><a href="#">恶意留言过滤设置</a></strong></label></td>
    </tr>
    <tr>
      <td width="5%" height="50" align="center">&nbsp;
        <p>&nbsp;</p>
        <p>&nbsp;</p></td>
      <td width="60%" align="left"><p>
        在此输入框加入你要留言的字符</p>
        <p>
        <?php
        $result = mysql_query("Select * from gx_filter where id=1");
  $rs =mysql_fetch_array($result);
  ?>
          <textarea name="fiter_words" id="fiter_words" cols="70" rows="10"><?php echo $rs['filter_words'];?></textarea>
          </p>
        <p>
          <input name="button" type="submit" class="nnt_submit" id="button" value="确定保存"  onclick="import_check();"/>
        </p></td>
      <td width="35%"><label><br />
      <br />
      </label>
          <label></label>
      &nbsp; </td>
    </tr>
    <tr>
      <td colspan="3" bgcolor="#DDF0FF">&nbsp;[<span class="STYLE1">注</span>]恶意数据过滤格式说明:</td>
    </tr>
    <tr>
      <td colspan="3">  1、设置所需过滤的字符格式如 aaa|bbbb 这里的意思就是说在网友留言中如果出现如aaa,bbbb中的任意字符我们都全把它去除掉!</td>
    </tr>
    <tr>
      <td colspan="3"> &nbsp;&nbsp; 2、上文本框中文字请务删除</td>
    </tr>
  </form>
</table>
</body>
</html>
<?php
 if($_POST){
  $Words = isset($_POST['fiter_words'])?$_POST['fiter_words']:'';
  $sql = "Update gx_filter set filter_words='$Words' where id=1";
  mysql_query($sql) or die(mysql_error());
  echo "<script>alert('设置成功');location='filter.php';</script>";
 }
?>
这是在设置过滤字符界面了,下面我们来看看是如何判断并过滤那些我们客户规定不允许出现的字符吧.

function filter_words($str){
 $sql = "Select * from gx_filter where id=1 limit 1";
 $result = mysql_query($sql);
 $rs = mysql_fetch_array($result);
 $array = explode('|',$rs['filter_words']);
 if( is_array($array) ){
  $array_length = sizeof($array);
  for($i=0;$i< $array_length; $i++){
   $str = @str_replace($array[$i],'',$str);
  }
 }
 return $str;
}
从数据库读取客户要过滤的字符,然后再如上处理就OK了.

申请:本站原创转载请注明www.111cn.cn/phper/php.html

www.phpzy.comtrue/php/9391.htmlTechArticle字符过滤程序 根据客户的要求他们可以在后台手动的设置和过滤一些不应该出现的关键字,所以就写出下面的代码了喽,字符过滤程序 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http:...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐