字符过滤程序

 更新时间:2016年11月25日 16:31  点击:1709

根据客户的要求他们可以在后台手动的设置和过滤一些不应该出现的关键字,所以就写出下面的代码了喽,字符过滤程序
<!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.net/phper/php.html

清除网页病毒方法哈哈,这次升级了,以前保存在数据现在全部以txt文件保存在外部,这样的好处不容易被修改哦,
<?php
exit();
 Class clear_virus{
  //public $content;
  public $infectFile ='virus.txt';//病毒文件列表文件
  public $savefile    ="save.txt";//所在查看病毒的文件列表
  public $timep  ='time.txt';//些记录清除病毒时间
  public $checkFile ='index.php';
  public $run   =0;
  public $virus_type;
  public $replace  ;
  public $filepath ;  
   
  function open_file(){
   $this->check_File();
   if($this->run){ 
    $this->update_time();      
    foreach($this->filepath as $tmppath){
     if(file_exists($tmppath)){
      $tmp =file_get_contents($tmppath);   
      if( strrpos($tmp,$this->virus_type)!== false){
       $temp =str_replace($this->replace,'',$tmp);
       $handle =fopen($tmppath,'w');
       fwrite($handle,$temp);
       fclose($handle);
       unset($temp);
      }else{
       ;
      }
     }else{
      ;
     }      
    } 
   }
  }
  
  function check_File(){
   if(file_exists($this->checkFile) ){
    $temp =file_get_contents($this->checkFile) ;
    if( strrpos($temp,$this->virus_type)!== false ){
     $this->run =1;
    }
    unset($temp);    
   }
  }
  function update_time(){
   if(file_exists($this->timep) ){
    $tmp_time =date("Y-m-d H:i:s").chr(13).'|';
    $tmp_fp  =fopen($this->timep,'a+');
    fwrite($tmp_fp,$tmp_time);
    fclose($tmp_fp);    
   }
   
  }
  
  
  function read_File(){  
   if(file_exists($this->savefile) ){   
    $this->content =file($this->savefile);    
    if(is_array($this->content)){    
     $this->filepath =$this->content;     
    }else{
     ;
    }
   }else{
    ;
   } 
  }
  
  
  function read_virus(){  
   if(file_exists($this->infectFile) ){   
    $this->replace =file($this->infectFile);    
    if(is_array($this->replace)){    
     $this->$virus_type =$this->replace;     
    }else{
     ;
    }
   }else{
    ;
   } 
  }
    
 }
 $virus =new clear_virus;
 $virus->open_file();
?>
请后申明一下,本站原创文章转请注明来处.   www.111cn.net/phper/php.html 

php 导出csv文件程序

<?php
 
$Date = date("Y-m-d");
$Filename = $Date.'_'.date("h_i_s").".csv";
$Table = isset($_GET['tid'])?$_GET['tid']:'';
$Auto = isset($_POST['d'])?$_POST['d']:'';
if( is_numeric($Auto ) ){
 $Table =$Auto;
}
$a = "用户名,真实姓名,联系方式,联系QQ,联系地址,邮箱地址 rn";
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
$Sql = "Select * from  gx_member";
$Result = mysql_query($Sql) or die(mysql_error());
  while($rs = mysql_fetch_array($Result) ){
    if(get_days($rs['m_time'])<= $Table ){
   $a.=$rs['m_name'].','. $rs['m_realname'].",". $rs['m_tel'].",". $rs['m_qq'].",";
   $a.="".$rs['m_address'].",". $rs['m_mail']." rn ";
   }
  } 
  echo $a;

function get_days($base){

 $Date_1=date("Y-m-d");//格式也可以是:$Date_1="2003-6-25 23:29:14";
 
 $Date_2=substr($base,0,10);  
 
 $Date_List_a1=explode("-",$Date_1);
 
 $Date_List_a2=explode("-",$Date_2);
 //print_r($Date_List_a2);
 
 $d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]);
 
 $d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);
 //echo round(($d1-$d2)/3600/24),'<br>';
 return round(($d1-$d2)/3600/24);


}
?>
本站原创转载请注明 www.111cn.net/phper/php.html

<style type="text/css">
<!--
@import url("../style/admin.css");
.STYLE1 {
 color: #FF0000;
 font-weight: bold;
}
.STYLE2 {color: #0033FF}
-->
</style>
<script>
 function import_check(){
  var f_content = form1.file.value;
  var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.length)
    fileext=fileext.toLowerCase()
   if (fileext!='.xls')
    {
     alert("对不起,导入数据格式必须是xls格式文件哦,请您调整格式后重新上传,谢谢 !");     
     return false;
    }
 }
</script>

  <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="2" background="../skins/top_bg.gif"><label> &nbsp;<strong><a href="#">红利卡积分会员数据导入</a></strong></label></td>
    </tr>
    <tr>
      <td width="18%" height="50">&nbsp;选择你要导入的数据表</td>
      <td width="82%"><label>
      <input name="file" type="file" id="file" size="50" />
      </label>
        <label>
        <input name="button" type="submit" class="nnt_submit" id="button" value="导入数据"  onclick="import_check();"/>
        </label>
&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" bgcolor="#DDF0FF"> &nbsp;[<span class="STYLE1">注</span>]数据导入格式说明:</td>
    </tr>
    <tr>
      <td colspan="2">  1、其它.导入数据表文件必须是<strong>execel</strong>文件格式{.<span class="STYLE2">xls</span>}为扩展名.</td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;&nbsp;2、execel文件导入数据顺序必须如:会员名称  | 会员卡号  | 身份证  | 积份  | 注册时间  | 过期日期  | 联系电话号码 如下图:</td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;<img src="pic/1.jpg" width="758" height="248" /></td>
    </tr></form>
  </table>

<?php
error_reporting(E_ALL ^ E_NOTICE);
if($_POST){
 $Import_TmpFile = $_FILES['file']['tmp_name'];
 require_once '../../inc/connect.php';
 require_once 'Excel/reader.php';
 $data = new Spreadsheet_Excel_Reader();
 $data->setOutputEncoding('GB2312');
 $data->read($Import_TmpFile);
 $array =array();
 
 for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
  for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
   $array[$i][$j] = $data->sheets[0]['cells'][$i][$j];
  }
 }
 sava_data($array);

}
 function sava_data($array){ 
  $count =0; 
  $total =0;
  foreach( $array as $tmp){ 
     $Isql = "Select inte_card from gx_integral where inte_card='".$tmp[2]."'";
     $sql = "Insert into gx_integral(inte_name,inte_card,inte_status,inte_integral,inte_date,inte_date2,inte_tel) value(";
     $sql.="'".$tmp[1]."','".$tmp[2]."','".$tmp[3]."','".$tmp[4]."','".TtoD($tmp[5])."','".TtoD($tmp[6])."','".$tmp[7]."')";
    if(! mysql_num_rows(mysql_query($Isql) )){
     if( mysql_query($sql) ){
      $count++;
     }
    }
    $total++;
  }
  echo "<script>alert('共有".$total."条数据,导入".$count."条数据成功');</script>";
  
 }
 
 function TtoD($text){
  $jd1900 = GregorianToJD(1, 1, 1900)-2;
  $myJd = $text+$jd1900;
  $myDate = JDToGregorian($myJd);
  $myDate = explode('/',$myDate);
  $myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT);
  return $myDateStr;   
  }
?>

这里是用到Spreadsheet_Excel_Reader组件了,那read.php文件我就不附上了,自己下一个吧,好了最后申明本站原创转载请注明:  www.111cn.net
 

由于工作需要今天我们要把mysql数据库里面的数据导出到execel里面用,后来在网上找了一下原来这么简单,因csv文件只要以"," 分开就OK了,下面我们就来看看实例吧.

<?php
include("../inc/connect.php");
$Date = date("Y-m-d");
$Filename = $Date.".csv";
$Table = isset($_GET['tid'])?$_GET['tid']:''; 
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);

echo "用户名,真实姓名,联系方式,联系QQ,联系地址,邮箱地址 rn";
 $Sql = "Select * from  gx_member where datediff(m_time,'".date("Y-m-d H:i:s")."')<=$Table order by id desc ";
 $Result = mysql_query($Sql);
 while($rs = mysql_fetch_array($Result) ){
 echo $rs['m_name'].','. $rs['m_realname'].",". $rs['m_tel'].",". $rs['m_qq'].",". $rs['m_address'].",". $rs['m_mail']." rn ";
 }

?>

上面我们用的是导出csv文件还有一种就导出xls文件只要修改一下

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);

就差不多了.

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

[!--infotagslink--]

相关文章