一个实例php mysql模板分页类

 更新时间:2016年11月25日 17:33  点击:1637
<?php教程
/*
 * 模板分页类,源于easp教程的数据库教程分页方法,算是easp分页的的php独立版
 * 支持动态和静态分页方式
 * * page([总记录数=1],[分页大小=20],[当前页=1],[显示页数=6],[分页参数='page'],[分页链接=当前页面],[是否静态=false])
 * 动态:
 * 简单用法:
 * $page = new page(50);
 * $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品&nbsp;&nbsp;当前第&nbsp;{pageindex}&nbsp;页&nbsp;/&nbsp;共&nbsp;{pagecount}&nbsp;页&nbsp;分页:&nbsp;{first}{prev}&nbsp;&nbsp;{list}&nbsp;&nbsp;{next}{last}&nbsp;&nbsp;转到&nbsp;{jump}&nbsp;页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 * 全参数用法:
 * $page = new page(50,20,1,6,'page','prrr.php',false);
 * $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品&nbsp;&nbsp;当前第&nbsp;{pageindex}&nbsp;页&nbsp;/&nbsp;共&nbsp;{pagecount}&nbsp;页&nbsp;分页:&nbsp;{first}{prev}&nbsp;&nbsp;{list}&nbsp;&nbsp;{next}{last}&nbsp;&nbsp;转到&nbsp;{jump}&nbsp;页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 * 静态:
 * $page = new page(50,20,1,6,'page','prrr{page}.html',true);
 * $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品&nbsp;&nbsp;当前第&nbsp;{pageindex}&nbsp;页&nbsp;/&nbsp;共&nbsp;{pagecount}&nbsp;页&nbsp;分页:&nbsp;{first}{prev}&nbsp;&nbsp;{list}&nbsp;&nbsp;{next}{last}&nbsp;&nbsp;转到&nbsp;{jump}&nbsp;页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
 * echo $page->getpager('zjj');
 */
class page {
 private $page_size; //每页显示的条目数
 private $total_size; //总条目数
 private $current_page; //当前被选中的页
 private $sub_pages; //每次显示的页数
 private $total_pages; //总页数
 private $page_tpl = array (); // 分页模板
 private $pageparam;
 private $pagelink;
 private $static;
 
 function __construct($total_size = 1, $page_size = 20, $current_page = 1, $sub_pages = 6, $pageparam = 'page', $pagelink = '', $static = false) {
  $this->page_size = intval ( $page_size );
  $this->total_size = intval ( $total_size );
  if (! $current_page) {
   $this->current_page = 1;
  } else {
   $this->current_page = intval ( $current_page );
  }
  $this->total_pages = ceil ( $total_size / $page_size );
  $this->sub_pages = intval ( $sub_pages );
  $this->pageparam = $pageparam;
  $this->pagelink = (empty ( $pagelink ) ? $_server ["php_self"] : $pagelink);
  $this->static = $static;
  $this->page_tpl ['default'] = array ('tpl' => '<div class="pager">{first}{prev}{liststart}{list}{listend}{next}{last} 跳转到{jump}页</div>', 'config' => array () );
 
 }
 public function __set($param, $value) {
  $this->$param = $value;
 }
 public function __get($param) {
  return $this->$param;
 }
 /*
  __destruct析构函数,当类不在使用的时候调用,该函数用来释放资源。
 */
 function __destruct() {
  unset ( $page_size ); //每页显示的条目数
  unset ( $total_size ); //总条目数
  unset ( $current_page ); //当前被选中的页
  unset ( $sub_pages ); //每次显示的页数
  unset ( $total_pages ); //总页数
  unset ( $page_tpl ); // 分页模板
  unset ( $pageparam ); //分页参数,默认page
  unset ( $pagelink );
  unset ( $static );
 }
 private function urlparameters($url = array()) {
  foreach ( $url as $key => $val ) {
   if ($key != $this->pageparam)
    $arg [] = $key . '=' . $val;
  }
  $arg [] = $this->pageparam . '=*';
  if ($this->static)
   return str_replace ( '{page}', '*', $this->pagelink );
  else
   return $this->pagelink . '?' . implode ( '&', $arg );
 }
 public function setpager($tpl_name = 'default', $tpl = '', $config = array()) {
  if (empty ( $tpl ))
   $tpl = $this->page_tpl ['default'] ['tpl'];
  if (empty ( $config ))
   $config = $this->page_tpl ['default'] ['config'];
  $this->page_tpl [$tpl_name] = array ('tpl' => $tpl, 'config' => $config );
 }
 public function getpager($tpl_name = 'default') {
  $this->getcurrentpage ();
  return $this->pager ( $this->page_tpl [$tpl_name] );
 }
 public function getcurrentpage() {
  $this->current_page = ($_get [$this->pageparam] <= intval ( $this->total_pages ) ? ($_get [$this->pageparam] < 1 ? 1 : $_get [$this->pageparam]) : intval ( $this->total_pages ));
 }
 public function pager($page_tpl = '') {
  if (empty ( $page_tpl ))
   $page_tpl = $this->page_tpl ['default'];
  $cfg = array ('recordcount' => intval ( $this->total_size ), 'pageindex' => intval ( $this->current_page ), 'pagecount' => intval ( $this->total_pages ), 'pagesize' => intval ( $this->page_size ), 'listlong' => intval ( $this->sub_pages ), 'listsidelong' => 2, 'list' => '*', 'currentclass' => 'current', 'link' => $this->urlparameters ( $_get ), 'first' => '&laquo;', 'prev' => '&#8249;', 'next' => '&#8250;', 'last' => '&raquo;', 'more' => '...', 'disabledclass' => 'disabled', 'jump' => 'input', 'jumpplus' => '', 'jumpaction' => '', 'jumplong' => 50 );
  if (! empty ( $page_tpl ['config'] )) {
   foreach ( $page_tpl ['config'] as $key => $val ) {
    if (array_key_exists ( $key, $cfg ))
     $cfg [$key] = $val;
   }
  }
  $tmps教程tr = $page_tpl ['tpl'];
  $pstart = $cfg ['pageindex'] - (($cfg ['listlong'] / 2) + ($cfg ['listlong'] % 2)) + 1;
  $pend = $cfg ['pageindex'] + $cfg ['listlong'] / 2;
  if ($pstart < 1) {
   $pstart = 1;
   $pend = $cfg ['listlong'];
  }
  if ($pend > $cfg ['pagecount']) {
   $pstart = $cfg ['pagecount'] - $cfg ['listlong'] + 1;
   $pend = $cfg ['pagecount'];
  }
  if ($pstart < 1)
   $pstart = 1;
  for($i = $pstart; $i <= $pend; $i ++) {
   if ($i == $cfg ['pageindex'])
    $plist .= '<span class="' . $cfg ['currentclass'] . '" >' . str_replace ( '*', $i, $cfg ['list'] ) . '</span> ';
   else
    $plist .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
  }
  if ($cfg ['listsidelong'] > 0) {
   if ($cfg ['listsidelong'] < $pstart) {
    for($i = 1; $i <= $cfg ['listsidelong']; $i ++) {
     $pliststart .= '<a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '">' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
    }
    $pliststart .= ($cfg ['listsidelong'] + 1) == $pstart ? '' : $cfg ['more'] . ' ';
   } else {
    if ($cfg ['listsidelong'] >= $pstart && $pstart > 1) {
     for($i = 1; $i <= ($pstart - 1); $i ++) {
      $pliststart .= '<a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '">' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
     }
    }
   }
   if (($cfg ['pagecount'] - $cfg ['listsidelong']) > $pend) {
    $plistend = ' ' . $cfg ['more'] . $plistend;
    for($i = (($cfg ['pagecount'] - $cfg ['listsidelong']) + 1); $i <= $cfg ['pagecount']; $i ++) {
     $plistend .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . ' </a> ';
    }
   } else {
    if (($cfg ['pagecount'] - $cfg ['listsidelong']) <= $pend && $pend < $cfg ['pagecount']) {
     for($i = ($pend + 1); $i <= $cfg ['pagecount']; $i ++) {
      $plistend .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . ' </a> ';
     }
    }
   }
  }
  if ($cfg ['pageindex'] > 1) {
   $pfirst = ' <a href="' . str_replace ( '*', '1', $cfg ['link'] ) . '">' . $cfg ['first'] . '</a> ';
   $pprev = ' <a href="' . str_replace ( '*', $cfg ['pageindex'] - 1, $cfg ['link'] ) . '">' . $cfg ['prev'] . '</a> ';
  } else {
   $pfirst = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['first'] . '</span> ';
   $pprev = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['prev'] . '</span> ';
  }
  if ($cfg ['pageindex'] < $cfg ['pagecount']) {
   $plast = ' <a href="' . str_replace ( '*', $cfg ['pagecount'], $cfg ['link'] ) . '">' . $cfg ['last'] . '</a> ';
   $pnext = ' <a href="' . str_replace ( '*', $cfg ['pageindex'] + 1, $cfg ['link'] ) . '">' . $cfg ['next'] . '</a> ';
  } else {
   $plast = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['last'] . '</span> ';
   $pnext = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['next'] . '</span> ';
  }
  switch (strtolower ( $cfg ['jump'] )) {
   case 'input' :
    $pjumpvalue = 'this.value';
    $pjump = '<input type="text" size="3" title="请输入要跳转到的页数并回车"' . (($cfg ['jumpplus'] == '') ? '' : ' ' . $cfg ['jumpplus']);
    $pjump .= ' onkeydown="网页特效:if(event.charcode==13||event.keycode==13){if(!isnan(' . $pjumpvalue . ')){';
    $pjump .= ($cfg ['jumpaction'] == '' ? ((strtolower ( substr ( $cfg ['link'], 0, 11 ) ) == 'javascript:') ? str_replace ( '*', $pjumpvalue, substr ( $cfg ['link'], 12 ) ) : " document.location.href='" . str_replace ( '*', ''+' . $pjumpvalue . '+'', $cfg ['link'] ) . '';') : str_replace ( "*", $pjumpvalue, $cfg ['jumpaction'] ));
    $pjump .= '}return false;}" />';
    break;
   case 'select' :
    $pjumpvalue = "this.options[this.selectedindex].value";
    $pjump = '<select ' . ($cfg ['jumpplus'] == '' ? ' ' . $cfg ['jumpplus'] . ' onchange="javascript:' : $cfg ['jumpplus']);
    $pjump .= ($cfg ['jumpaction'] == '' ? ((strtolower ( substr ( $cfg ['link'], 0, 11 ) ) == 'javascript:') ? str_replace ( '*', $pjumpvalue, substr ( $cfg ['link'], 12 ) ) : " document.location.href='" . str_replace ( '*', ''+' . $pjumpvalue . '+'', $cfg ['link'] ) . '';') : str_replace ( "*", $pjumpvalue, $cfg ['jumpaction'] ));
    $pjump .= '" title="请选择要跳转到的页数"> ';
    if ($cfg ['jumplong'] == 0) {
     for($i = 0; $i <= $cfg ['pagecount']; $i ++) {
      $pjump .= '<option value="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="selected"' : '') . ' >' . $i . '</option> ';
     }
    } else {
     $pjumplong = intval ( $cfg ['jumplong'] / 2 );
     $pjumpstart = ((($cfg ['pageindex'] - $pjumplong) < 1) ? 1 : ($cfg ['pageindex'] - $pjumplong));
     $pjumpstart = ((($cfg ['pagecount'] - $cfg ['pageindex']) < $pjumplong) ? ($pjumpstart - ($pjumplong - ($cfg ['pagecount'] - $cfg ['pageindex'])) + 1) : $pjumpstart);
     $pjumpstart = (($pjumpstart < 1) ? 1 : $pjumpstart);
     $j = 1;
     for($i = $pjumpstart; $i <= $cfg ['pageindex']; $i ++, $j ++) {
      $pjump .= '<option value="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="selected"' : '') . '>' . $i . '</option> ';
     }
     $pjumplong = $cfg ['pagecount'] - $cfg ['pageindex'] < $pjumplong ? $pjumplong : $pjumplong + ($pjumplong - $j) + 1;
     $pjumpend = $cfg ['pageindex'] + $pjumplong > $cfg ['pagecount'] ? $cfg ['pagecount'] : $cfg ['pageindex'] + $pjumplong;
     for($i = $cfg ['pageindex'] + 1; $i <= $pjumpend; $i ++) {
      $pjump .= '<option value="' . $i . '">' . $i . '</option> ';
     }
    }
    $pjump .= '</select>';
    break;
  }
  $patterns = array ('/{recordcount}/', '/{pagecount}/', '/{pageindex}/', '/{pagesize}/', '/{list}/', '/{liststart}/', '/{listend}/', '/{first}/', '/{prev}/', '/{next}/', '/{last}/', '/{jump}/' );
  $replace = array ($cfg ['recordcount'], $cfg ['pagecount'], $cfg ['pageindex'], $cfg ['pagesize'], $plist, $pliststart, $plistend, $pfirst, $pprev, $pnext, $plast, $pjump );
  $tmpstr = chr ( 13 ) . chr ( 10 ) . preg_replace ( $patterns, $replace, $tmpstr ) . chr ( 13 ) . chr ( 10 );
  unset ( $cfg );
  return $tmpstr;
 }
}
?>
ajax只支持utf-8格式,不能支持gb2312编码格式,所以经常遇到gb2312的编码的程序使用ajax就出现乱码,刚找到一种解决方案是

服务器端传送的数据仍是gb2312编码,客户端用js将汉字转变成utf8编码显示在页面

方法一json
一,服务器端json数据用php教程的iconv函数转换:iconv('gb2312', 'utf8', "被转换字符串,输出到浏览器"); 
      客户端获取utf8数据,再转成gb2312:

function gb2utf8(data){//gb编码是,ie通过二进制码utf8->gbk转为中文 
     var glbencode = []; 
     gb2utf8_data = data; 
     execscript("gb2utf8_data = midb(gb2utf8_data, 1)", "vbscript"); 
     var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g|>,"%$2%$1").replace(/%([a-z].)%(.{2})/g|>,"@$1$2"); 
     t=t.split("@"); 
     var i=0,j=t.length,k; 
     while(++i<j)> 
         k=t.substring(0,4); 
         if(!glbencode[k]) { 
             gb2utf8_char = eval("0x"+k); 
             execscript("gb2utf8_char = chr(gb2utf8_char)", "vbscript"); 
             glbencode[k]=escape(gb2utf8_char).substring(1,6); 
         } 
         t=glbencode[k]+t.substring(4); 
     } 
     gb2utf8_data = gb2utf8_char = null; 
     return unescape(t.join("%")); 
}

二,header("content-type", "application/x-www-form-urlencoded; charset=gbk"); //输出头标,设置为gbk编码

三,在ajax请求数据前调用上面的方法指定请求使用的字符集:xmlhttp.setrequestheader( "content-type", "application/x-www-form-urlencoded;charset=gbk");


方案二
search.php

<?php
header("content-type: text/html; charset=gb2312");
include './search.htm';
?>

search.htm

<!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>
<h3>高级搜索</h3>
<form method="post" action="">
  学校类型:
  <select name="schooltype">
    <option value="">全部</option>
    <option value="1">小学</option>
    <option value="2">初中</option>
  </select>
  学校名称:
  <select name="sid" id="sid">
    <option value="">请选择学校</option>
  </select>
</form>
<script type="text/网页特效">
function ajax(settings) {
    var xhr = window.activexobject ? new activexobject("microsoft.xmlhttp") : new xmlhttprequest(), successed = false;
    xhr.open(settings.type, settings.url);
    if(settings.type == 'post')
     xhr.setrequestheader('content-type', 'application/x-www-form-urlencoded');
    xhr.send((!settings.cache ? 'time=' + new date().gettime() + '&' : '') + settings.data);
    settings.loader();
    settimeout(function() {
        if(!successed) {
            alert('resquest timeout!');
            xhr.abort();
        }
    }, settings.timeout);
    xhr.onreadystatechange = function() {
        if (xhr.readystate == 4 && xhr.status == 200) {
            settings.callback(xhr.responsetext.replace(/(^s*)|(s*$)/g, ""));
        }
        successed = true;
    }
}
function a(t) {
ajax({
  type: 'post',
  url: 'ajax.php',
  data: 'schooltype=' + t,
  timeout: 8000,
  cache: true,
  loader: function() {},
  callback: function(d) {
   var arr = eval(d);
   if(typeof(arr) == 'object') {
    var obj, option;
    document.getelementbyid('sid').innerhtml = '';
    for(var i = 0; obj = arr; i ++) {
     option = document.createelement('option');
     option.value = obj[0];
     option.innerhtml = txt2utf8(obj[1], '&#');
     document.getelementbyid('sid').appendchild(option);
    }
   }
  }
})
}
function txt2utf8(string, prefix){
    for(var i=0,utf8=[];i<string.length;utf8.push((prefix||'u')+string.charcodeat(i++)));
    return utf8.join('');
}
a(0);
</script>
</body>
</html>

ajax.php
<?php
header("content-type: text/html; charset=gb2312");
$schooltype = !empty($_post['schooltype']) ? $_post['schooltype'] : 0;
switch($schooltype) {
    case 0:
        echo "[['40', '太平溪镇花栗包完全小学'],['41', '太平溪镇长岭黑龙江希望小学'],['42', '乐天溪镇初级中学'],['43', '乐天溪镇莲沱初级中学']]";
        break;
    case 1:
        echo "[['40', '太平溪镇花栗包完全小学'],['41', '太平溪镇长岭黑龙江希望小学']]";
        break;
    case 2:
        echo "[['42', '乐天溪镇初级中学'],['43', '乐天溪镇莲沱初级中学']]";
        break;
    default:
        break;
}
?>

本款文件上传类,默认是上传单文件的,我们只要修改$inputname ='files'为你的表单名就可以方便的实现批量文件上传了。 $savename = ''保存文件名, $alowexts = array()设置允许上传的类型,$savepath = ''保存路径。
*/

 代码如下 复制代码

class upload
{
 public $savepath;
 public $files;
 private $error;

 function __construct($inputname ='files', $savepath = '', $savename = '', $alowexts = array(),$maxsize = 1024000)
 {
  if(!$alowexts)$alowexts=explode('|',upload_ftype);
  $file_array=array();
  $savepath=str_replace('','/',$savepath);
  $savename=preg_replace('/[^a-z0-9_]+/i','',$savename);
  $this->savepath=substr($savepath,-1)=='/'?$savepath:$savepath.'/'; //路径名以/结尾

  if(!make_dir($this->savepath))
  {
   $this->error=8;
   $this->error();
  }
  //exit($this->savepath);
  if(!is_writeable($this->savepath))
  {
   $this->error=9;
   $this->error();
  }
  if(sizeof($_files[$inputname]['error'])>10)
  {
   $this->error=13;
   $this->error();
  }
  $max=sizeof($_files[$inputname]['error'])-1;
  //exit($this->savepath.$savename);
  foreach($_files[$inputname]['error'] as $key => $error)
  {
   if($error==upload_err_ok) //批量上传
   {
    $savename=$savename?$savename:date('ymdims').mt_rand(10000,99999);
    $fileext=strtolower(get_fileext($_files[$inputname]['name'][$key]));
    $savename=$savename.'.'.$fileext;
    $tmp_name=$_files[$inputname]['tmp_name'][$key];
    $filesize=$_files[$inputname]['size'][$key];
    if(!in_array($fileext,$alowexts))
    {
     $this->error=10;
     $this->error();
    }
    if($filesize>$maxsize)
    {
     $this->error=11;
     $this->error();
    }
    if(!$this->isuploadedfile($tmp_name))
    {
     $this->error=12;
     $this->error();
    }

    if(move_uploaded_file($tmp_name,$this->savepath.$savename) || @copy($tmp_name,$this->savepath.$savename))
    {
     //exit($this->savepath.$savename);
     @chmod($savename, 0644);
     @unlink($tmp_name);
     $file_array[]=$this->savepath.$savename;     
    }
   }
   else
   {
    $this->error=$error;
    $this->error();
   }
   unset($savename);
  }
  $this->files=$file_array;
  return true;
 }

 function isuploadedfile($file) //去掉系统自带的反斜线
 {
  return (is_uploaded_file($file) || is_uploaded_file(str_replace('\','',$file)));
 }

 function error()
 {
  $upload_error=array(0 => '文件上传成功 !',
       1 => '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值 !',
       2 => '上传文件的大小超过了 html 表单中 max_file_size 选项指定的值 !',
       3 => '文件只有部分被上传 !',
       4 => '没有文件被上传 !',
       5 => '未知错误!',
       6 => '找不到临时文件夹。 !',
       7 => '文件写入临时文件夹失败 !',
       8 => '附件目录创建失败 !',
       9 => '附件目录没有写入权限 !',
       10 => '不允许上传该类型文件 !',
       11 => '文件超过了管理员限定的大小 !',
       12 => '非法上传文件 !',
       13 => '最多可同时上传10个文件 !'
       );
  showmsg($upload_error[$this->error]);
 }

}

//使用方法

new upload();

 代码如下 复制代码

*/
header('content-type: text/html; charset=utf-8');
require('function.php');

$url = strtolower(trim($_get['url']));
$lm = intval($_get['lm']);
$pn = intval($_get['pn']);

$url = getshorturl($url);

if (empty($pn)) $pn = 1;

switch ($lm) {
 case 1 :
  $timestr = '24小时';
  break;
 case 7 :
  $timestr = '一星期';
  break;
 case 30 :
  $timestr = '一个月';
  break;
 case 360 :
  $timestr = '一年';
  break;
 default :
  $timestr = '所有时间';
  break;
}
?>
<!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>
<?php
if (empty($url)) {
?>
<title>35dir百度近日收录查询-35分类目录</title>
<meta name="keywords" content="百度近日收录查询" />
<meta name="description" content="百度近日收录查询可按指定时间段(最近24小时、一星期、一个月、一年、所有时间)查询,让你及时了解网站在某一时间段内的收录情况。" />
<?php
} else {
?>
<title><?php echo $url;?>百度最近<?php echo $timestr; ?>收录详情-35分类目录</title>
<meta name="keywords" content="<?php echo $url; ?>,百度近日收录查询" />
<meta name="description" content="<?php echo $url; ?>,百度最近<?php echo $timestr; ?>收录查询结果。" />
<?php
}
?>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="copyright" content="powered by 111cn.net" />
<meta http-equiv="pragma" content="no-cache" />
<script type="text/网页特效" src="jquery.js"></script>
<script type="text/jscript">
function checkfrm() {
 if ($("#url").attr("value") == "") {
  alert("请输入要查询的域名!");
  $("#url").focus();
  return false;
 } else {
  var reexp = /^([a-z0-9-]{1,}.)?[a-z0-9-]{2,}.([a-z0-9-]{1,}.)?[a-z0-9]{2,}$/i;
  if (!reexp.test($("#url").attr("value"))) {
   alert("请输入正确的域名!");
   $("#url").focus();
   return false;
  }
 }
 return true;
}
</script>
<link href="skin/style.css教程" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="topbar">网站导航:<a href="http://www.111cn.net/" target="_blank">35分类目录</a> | <a href="http://www.opdir.cn/" target="_blank">open directory</a></div>
<div id="container">
 <div id="header">
     <a class="logo" href="http://tool.111cn.net/baidu/" title="35dir百度近日收录查询"></a>
     <div id="search">
          <form name="myso" method="get" action="" onsubmit="return checkfrm();">
   <span style="font: bold 16px normal;">http://</span> <input name="url" id="url" type="text" size="50" class="sipt" value="<?php echo $url;?>" />
                <input type="hidden" name="lm" value="1" />
    <input type="submit" class="sbtn" value="查 询" />
              <div class="tips教程">示例:<a href="javascript: void(0);" onclick="$('#url').attr('value', '111cn.net')">111cn.net</a>,<a href="javascript: void(0);" onclick="$('#url').attr('value', 'www.111cn.net')">www.111cn.net</a>,带"www"与不带"www"的查询结果不同</div>
          </form>
        </div>
 </div>
    <?php
 if (!empty($url)) {
 ?>
    <div class="tool"><strong>按时间段查询:</strong> <a href="">最近24小时</a>  <a href="">最近一星期</a>  <a href="">最近一个月</a>  <a href="">最近一年</a>  <a href="">总收录量</a></div>
  <div id="mainer">
     <?php
  $query_url = 'http://www.baidu.com/s?wd=site%3a'.$url.'&pn='.$pn.'&lm='.$lm;
  $line_arr = @file($query_url);
   
  $content = implode('###', $line_arr);
  $content = @mb_convert_encoding($content, 'utf-8', 'gb2312');
  
  //index
  if (preg_match('/找到相关网页(.*?)篇/i', $content, $index)) {
   $baiduindex = str_replace('约', '', $index[1]);
  } else {
   $baiduindex = '-';
  }
  ?>
     <div class="content">
      <h2>百度在最近 <font color="#ff6600"><?php echo $timestr; ?></font> 内共收录了网站( <a href="<?php echo getfullurl($url); ?>" target="_blank"><?php echo $url; ?></a> ) <font color="#ff6600"><?php echo $baiduindex; ?></font> 个页面</h2>
         <div>
   <?php
   $content = strstr($content, '<table cellpadding="0" cellspacing="0" class="result"');
   $end = strpos($content, '<div id="search">');
   $content = substr($content, 0, $end);
   
   $item_arr = explode('<tr><td class=f>', $content);
 
   //showpage
   if (preg_match('/<p id="page">(.*?)</div>/', $content, $page_arr)) {
    $showpage = str_replace('s?wd=site%3a', '?url=', $page_arr[1]);
    $showpage = str_replace('[', '', $showpage);
    $showpage = str_replace(']', '', $showpage);
   }
 
   $i = 0;
   $strhtml = '<ul class="sitelist">';
   foreach ($item_arr as $item) {
    if (preg_match('/<a  onmousedown="(.*?)" href="(.*?)"  target="_blank" ><font size="3">(.*?)</font></a><br><font size=-1>(.*?)<font color="#008000">(.*?)</font> - <a href="(.*?)"  target="_blank"  class="m">/i', $item, $siteinfo)) {
     $sitename = $siteinfo[3];
     $siteurl = $siteinfo[2];
     $sitedesc = $siteinfo[4];
     $siteltime = $siteinfo[5];
     $sitecache = $siteinfo[6];
     
     $strhtml .= '<li>';
     $strhtml .= '<strong><em>'.$i.'.</em><a href="'.$siteurl.'" target="_blank">'.$sitename.'</a></strong>';
     $strhtml .= '<p>'.$sitedesc.'</p>';
     $strhtml .= '<address>'.$siteltime.' - <a href="'.$sitecache.'" target="_blank">百度快照</a></address>';
     $strhtml .= '</li>';
    }
    $i++;
   }
   $strhtml .= '</ul>';
   $strhtml .= '<div class="showpage">'.$showpage.'</div>';
 
   echo $strhtml;
   ?>
      </div>
  </div>
  </div>
    <?php
    }
 ?>
  
</div>
</body>
</html>

function文件

<?php
function getfullurl($url) {
 if ($url != "") {
  $url_parts = parse_url($url);
  if ($url_parts['scheme'] == "") {
   $url = "http://".$url;
  }
 }
 return $url;
}
 
function getshorturl($url) {
 if ($url != "") {
  $url_parts = parse_url($url);
        if ($url_parts['host'] == "") {
   $url = $url_parts['path'];
  } else {
            $url = $url_parts['host'];
        }
 }
 return $url;
}
 
function format_number($number) {
 if ($number == '') return "-";
 $nlen = strlen($number);
 while ($nlen > 3) {
  $fnumber = ",".substr($number, $nlen - 3, 3).$fnumber;
  $number = substr($number, 0, -3);
  $nlen = strlen($number);
 }
  
 if ($nlen <= 3) {
  $fnumber = $number.$fnumber;
 }
 return $fnumber;
}
?>

源码下载地址

http://down.111cn.net/s/2010/1025/21415.html

文章利用了二个实例来讲述一下关于php 设置cookie与 读取cookie及cookie删除等处理方法

如果需要更新cookie以让其储存新值,只需要将其原值覆盖即可。因此,即使你已经在之前的页面中刚刚发送cookie,仍可以将你的名字改为"jeff"。
*/

 代码如下 复制代码

$y2k = mktime(0,0,0,1,1,2000);

setcookie('name', 'jeff', $y2k);


/*
上面是个简单的cookie实例,下面我们来看个复杂的cookie 来作用户登录验证实例代码。
*/

 代码如下 复制代码

function verify()
{
  global $pass;
  if($_post['pass'] == $pass || $_cookie['pass'] == md5($pass))
  {
    cookie(true);
    return true;
  }
  else
  {
    cookie(false);
    return false;
  }
}

function cookie($set = true)
{
  global $pass;
  if($set)
    setcookie("pass",md5($pass),time()+3600);
  else
    setcookie("pass","",time()-3600);
}

[!--infotagslink--]

相关文章

  • php KindEditor文章内分页的实例方法

    我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • 深入解析WordPress中加载模板的get_template_part函数

    这篇文章主要介绍了WordPress中加载模板的get_template_part函数,其中重点讲解了其函数钩子的使用,需要的朋友可以参考下...2016-01-14
  • vue.js 表格分页ajax 异步加载数据

    Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20
  • mysql配置模板(my-*.cnf)参数详细说明

    mysql安装成功后有几个默认的配置模板,列表如下: my-huge.cnf : 用于高端产品服务器,包括1到2GB RAM,主要运行mysql my-innodb-heavy-4G.ini : 用于只有innodb的安装,最多有4GB RAM,支持大的查询和低流量 my-large.cnf : 用于...2015-03-15
  • Springboot如何使用mybatis实现拦截SQL分页

    这篇文章主要介绍了Springboot使用mybatis实现拦截SQL分页,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-19
  • PHP 一个完整的分页类(附源码)

    在php中要实现分页比起asp中要简单很多了,我们核心就是直接获取当前页面然后判断每页多少再到数据库中利用limit就可以实现分页查询了,下面我来详细介绍分页类实现程序...2016-11-25
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • AngularJS实现分页显示数据库信息

    这篇文章主要为大家详细介绍了AngularJS实现分页显示数据库信息效果的相关资料,感兴趣的小伙伴们可以参考一下...2016-07-06
  • Smarty模板学习笔记之Smarty简介

    1、简介Smarty是一个使用PHP写出来的模板PHP模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。简单的讲,目...2014-05-31
  • 基于jquery实现表格无刷新分页

    这篇文章主要介绍了基于jquery实现表格无刷新分页,功能实现了前端排序功能,增加了前端搜索功能,感兴趣的小伙伴们可以参考一下...2016-01-08
  • vue实现页面打印自动分页的两种方法

    这篇文章主要为大家详细介绍了vue实现页面打印自动分页的两种方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-29
  • Ionic默认的Tabs模板使用实例

    这篇文章主要为大家详细介绍了Ionic默认的Tabs模板使用实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-09-01
  • Springboot使用thymeleaf动态模板实现刷新

    这篇文章主要介绍了Springboot使用thymeleaf动态模板实现刷新,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-08-31
  • vue.js表格分页示例

    这篇文章主要为大家详细介绍了vue.js表格分页示例,ajax异步加载数据...2016-10-20
  • C# DataTable分页处理实例代码

    有时候我们从数据库获取的数据量太大,而我们不需要一次性显示那么多的时候,我们就要对数据进行分页处理了,让每页显示不同的数据。...2020-06-25
  • 原生js实现分页效果

    这篇文章主要为大家详细介绍了原生js实现分页效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-09-24
  • Python优化列表接口进行分页示例实现

    最近,在做测试开发平台的时候,需要对测试用例的列表进行后端分页,在实际去写代码和测试的过程中,发现这里面还是有些细节的,故想复盘一下...2021-09-29
  • WordPress中获取所使用的模板的页面ID的简单方法

    这篇文章主要介绍了WordPress中获取所使用的模板的页面ID的简单方法,通过这个方法来获取页面的链接是比较方便的,需要的朋友可以参考下...2016-01-04