php ajax分页代码

header("content-type: text/html;charset=gbk");//输出编码,避免中文乱码
?>
<html>
<head>
<title>ajax分页演示</title>
<script language="网页特效" >
var http_request=false;
  function send_request(url){//初始化,指定处理函数,发送请求的函数
    http_request=false;
 //开始初始化xmlhttprequest对象
 if(window.xmlhttprequest){//mozilla浏览器
  http_request=new xmlhttprequest();
  if(http_request.overridemimetype){//设置mime类别
    http_request.overridemimetype("text/xml");
  }
 }
 else if(window.activexobject){//ie浏览器
  try{
   http_request=new activexobject("msxml2.xmlhttp");
  }catch(e){
   try{
   http_request=new activexobject("microsoft.xmlhttp");
   }catch(e){}
  }
    }
 if(!http_request){//异常,创建对象实例失败
  window.alert("创建xmlhttp对象失败!");
  return false;
 }
 http_request.onreadystatechange=processrequest;
 //确定发送请求方式,url,及是否同步执行下段代码
    http_request.open("get",url,true);
 http_request.send(null);
  }
  //处理返回信息的函数
  function processrequest(){
   if(http_request.readystate==4){//判断对象状态
     if(http_request.status==200){//信息已成功返回,开始处理信息
   document.getelementbyid(reobj).innerhtml=http_request.responsetext;
  }
  else{//页面不正常
   alert("您所请求的页面不正常!");
  }
   }
  }
  function dopage(obj,url){
   document.getelementbyid(obj).innerhtml="<font color='green' font-size='12'>正在读取数据...</font>";
   send_request(url);
   reobj=obj;
   }
 
</script>
<style>
/* css教程 document */
#result ul li{
 height:20px;
 width:auto;
 display:block;
 color:#999;
 border:1px solid #999;
 float:left;
 list-style:none;
 font-size:12px;
 margin-left:5px;
 line-height:20px;
 vertical-align:middle;
 text-align:center;
 }
#result ul li a:link{
 width:50px;
 height:20px;
 display:block;
 
 line-height:20px;
 background:#09c;
 border:1px solid #fff;
 color:#fff;
 text-decoration:none;
 }
#result ul li a:hover{
 width:50px;
 height:20px;
 display:block;
 
 line-height:20px;
 background:#09c;
 border:1px solid #fff;
 color:#f60;
 text-decoration:none;
 }
</style>
</head>
<body>
<div id="result">
<?php
$page=isset($_get['page'])?intval($_get['page']):1;        //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。
$num=10;                                      //每页显示10条数据

阅读全文

php递归删除目录所有文件

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<?php
function tree($directory)
{
$mydir=dir($directory);
echo "<ul> ";
while($file=$mydir->read()){
if((is_dir("$directory/$file")) and ($file!=".") and ($file!=".."))
{echo "<li><font color="#ff00cc"><b>$file</b></font></li> ";
tree("$directory/$file");
}
else{
    $a = explode('.',$file);
    if($a[1] == 'html' || $a[1] == 'htm')
   {
        //unlink($file);
            echo "<li>$file</li> ";
        }   
   

阅读全文

PHP实现URL静态化

再有一种就是伪静态方式,即用户和搜索引擎看到的是.html后缀的静态页面,但实际上它还是动态程序,只不过是通过某种方式进行了伪装。

这种方式也有两种实现方式:

阅读全文

php获取文件大小并转换gb,mb,kb代码

function sizecount($filesize) {
 if($filesize >= 1073741824) {
  $filesize = round($filesize / 1073741824 * 100) / 100 . ' gb';
 } elseif($filesize >= 1048576) {
  $filesize = round($filesize / 1048576 * 100) / 100 . ' mb';
 } elseif($filesize >= 1024) {
  $filesize = round($filesize / 1024 * 100) / 100 . ' kb';
 } else {
  $filesize = $filesize . ' bytes';
 }
 return $filesize;
}

阅读全文

php数据库备份还原函数

//备份还原函数

function write_file($sql,$filename) {
    $re=true;
    if(!@$fp=fopen("./www.phprm.com/".$filename,"w+")) {$re=false; echo "failed to open target file";}
    if(!@fwrite($fp,$sql)) {$re=false; echo "failed to write file";}
    if(!@fclose($fp)) {$re=false; echo "failed to close target file";}
    return $re;
}
function down_file($sql,$filename){
 ob_end_clean();
 header("content-encoding: none");
 header("content-type: ".(strpos($_server['http_user_agent'], 'msie') ? 'application/octetstream' : 'application/octet-stream'));

阅读全文

mysql 数据库操作类

class dbstuff {
 var $querynum = 0;
 var $link;
    var $sqlid;
    var $record;
    var $dbcharset='utf-8';
    var $charset='utf-8';
 function connect($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0, $halt = true) {
  if($pconnect) {
   if(!$this->link = @mysql_pconnect($dbhost, $dbuser, $dbpw)) {
    $halt && $this->halt('can not connect to mysql server');
   }
  } else {
   if(!$this->link = @mysql_connect($dbhost, $dbuser, $dbpw, 1)) {
    $halt && $this->halt('can not connect to mysql server');
   }
  }

阅读全文

ob_start()、ob_end_clean()、ob_get_contents()函数

三个函数吧:"ob_start()、ob_end_clean()、ob_get_contents()"

ob_start():是打开缓冲区的,就是要把您需要生成的静态文件的内容缓存在这里;
ob_get_contents():是读出缓冲区里的内容,下面有代码为例;
ob_end_clean():这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来;

阅读全文