Home > Backend Development > PHP Tutorial > Character Filter_PHP Tutorial

Character Filter_PHP Tutorial

WBOY
Release: 2016-07-13 17:07:19
Original
768 people have browsed it

According to customer requirements, they can manually set and filter some keywords that should not appear in the background, so I wrote the following code, character filtering program




Untitled Document




 
   
     
   
   
     
     
     
   
   
     
   
   
     
   
   
     
   
 
 
       

 


       

 


        在此输入框加入你要留言的字符


       


                $result = mysql_query("Select * from gx_filter where id=1");
  $rs =mysql_fetch_array($result);
  ?>
         
         


       


         
       


         
       
 []恶意数据过滤格式说明:
 1、设置所需过滤的字符格式如 aaa|bbbb 这里的意思就是说在网友留言中如果出现如aaa,bbbb中的任意字符我们都全把它去除掉!
   2、上文本框中文字请务删除



 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;
}
Read the characters that the customer wants to filter from the database, and then process them as above.

Application: For original reprints on this site, please indicate www.111cn.cn/phper/php.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630428.htmlTechArticleAccording to customer requirements, they can manually set and filter some keywords that should not appear in the background, so I wrote Here is the code below, character filter program! DOCTYPE html PUBLIC -//...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template