php 文章内容分页代码

 更新时间:2016年11月25日 16:27  点击:2047
php 文章内容分页代码,是根据由编辑器插入的分页符来操作了,我们可以分出超漂亮的偏移效果的分页。

 * author:陈凯
 * data:2010-09-15
 * 文章分页类
 */

 代码如下 复制代码

class contentpage
{
 private $content;  //文章内容
 private $pagesize;    //每页最少字节数
 private $breakflag;  //分页符(可以自定义,默认为)
 private $pageurl;  //url地址
 private $pagevar;  //分页参数
 public  $pagecount;  //总页数
 public  $page;   //当前页码
 public  $pagebreak;  //每页起始位置

 function __construct($content = "",$pagesize = 10,$breakflag =" ",$pageurl = '',$pagevar = 'p')
 {
  $this->content   = $content;
  $this->pagesize  = $pagesize;
  $this->breakflag = $breakflag;
  $this->pageurl   = $pageurl;
  $this->pagevar   = $pagevar;
  $this->getpages();
 }

 //总页数,每页的起始位置和结束位置
 public function getpages()
 {
  $contentlen   = strlen($this->content); //文章总字节数
  $this->pagebreak[0] = 0;
  $i = 0;
  $offset = $this->pagesize;
  
  for ($k=0;$k<$contentlen/$this->pagesize;$k++)
  {
   if($offset > $contentlen)
   {
    $i++;
    $this->pagebreak[$i] = $contentlen;
    break;
   }
   //查找$this->pagevar出现的位置
   $where = strpos($this->content,$this->breakflag,$offset);
   if($where > $contentlen or intval($where) < 1)
   {
    $i++;
    $this->pagebreak[$i] = $contentlen;
    break;
   }
   else
   {
    $i++;
    $this->pagebreak[$i] = $where;
    $offset = $where + $this->pagesize;
   }
  }
  $this->pagecount = $i;
  if(isset($_get[$this->pagevar]) && $_get[$this->pagevar] >1 && $_get[$this->pagevar] <= $this->pagecount)
  {
   $this->page = $_get[$this->pagevar];
  }
  else
  {
   $this->page = 1;
  }
 }

 //每页内容
 function getpage()
 {
  //截取当前页码的数据
  if($this->page > 1)
  {
   return substr($this->content,$this->pagebreak[$this->page-1]+1,$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
  }
  else
  {
   return substr($this->content,$this->pagebreak[$this->page-1],$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
  }

 }

 //分页条
 public function getpagenav()
 {
  if($this->page > 1)
  {
   $pagenav = "<a href='".$this->geturl()."=".($this->page-1)."' class='div'>上一页</a>&nbsp;&nbsp;";
  }

  //输出数字页码
  for($j=1;$j<=$this->pagecount;$j++)
  {
   if($j == $this->page)
   {
    $pagenav .= "<span class='divsi'>".$j."</span>&nbsp;&nbsp;";
   }
   else
   {
    $pagenav .= "<a href='".$this->geturl()."=".$j."' class='div'>".$j."</a>&nbsp;&nbsp;";
   }
  }
  //下一页
  if($this->page < $this->pagecount && $this->pagecount >1)
  {
   $pagenav .= "<a href='".$this->geturl()."=".($this->page+1)."' class='div'>下一页</a>&nbsp;&nbsp;";
  }
  return $pagenav;
 }
 //获取url地址
 public function geturl()
 {
  $url = $_server['request_uri'];
  $parse_url = parse_url($url);
  $query_url = $parse_url['query'];
  
  if($query_url)
  {
   $query_url = ereg_replace("(^|&)".$this->pagevar."=".$this->page,"",$query_url);
   $url = str_replace($parse_url['query'],$query_url,$url);
   if($query_url)
   {
    $url .= "&".$this->pagevar;
   }
   else
   {
    $url .= $this->pagevar;
   }
  }
  else
  {
   $url .= "?".$this->pagevar;
  }
  return $url;
 }
}

$content = "第一页:文章内容分页阿斯顿浪费空间阿斯顿来看福建省地方吉林省福建路口附近大手拉飞机上浪费的说浪费监理费
第二页:阿斯顿房间阿双方了解啊对萨拉开发记得谁来付款将令对方空间的来福建阿里是否
第三页:欧文炯诶哦生地拉开方面来看就继续超文章内容分页滤机蓝卡
第四页:欧文日据拉萨及发动四分啊就双方的将爱是发觉是文章内容分页否了。";
$model = new contentpage($content);
echo $model->getpage();  //输出分页内容
echo $model->getpagenav(); //输出页码
?>

<style type="text/css教程">
<!--
body {
 width:800px;
 margin:0 auto;
 margin-top:50px;
 font-size:12px;
}
a {
 color:#014ccc;
 text-decoration:none;
}
.div {
 float:left;
 cursor:pointer;
 font-weight:bold;
 margin-right:5px;
 display: block;
 padding:3px 7px;
 text-align:center;
 border:#bbdded solid 1px;
}
.divs {
 float:left;
 font-weight:bold;
 margin-right:5px;
 display: block;
 padding:3px 7px;
 text-align:center;
 border:#cccccc solid 1px;
}
.divsi {
 float:left;
 font-weight:bold;
 margin-right:5px;
 display: block;
 padding:3px 7px;
 text-align:center;
 background:#3399ff;
 color:#ffffff;
 border:#cccccc solid 1px;
}
.div:hover {
 background:#3399ff;
 color:#ffffff;
}
.divsi:hover {
 background:#3399ff;
 color:#ffffff;
}

-->
</style>

本函数php自定义函数是一款建立文件夹的路径并且支持多级目录实例函数哦。
 代码如下 复制代码

 * create_dir(建立文件夹的路径,支持多级目录);
 */
 function create_dir($dir_adds='') {
  $falg = true;
  $dir_adds  = trim($dir_adds);
  if($dir_adds!=''){
   $dir_adds = str_replace(array('//','\','\\'),'/',$dir_adds);
   if (!is_dir($dir_adds)) {
    $temp = explode('/',$dir_adds);
    $cur_dir = '';
    for($i=0;$i<count($temp);$i++){
     $cur_dir .= $temp[$i].'/';
     if (!@is_dir($cur_dir)) {
      if(!@mkdir($cur_dir,0777))
       $falg = false;
     }
    }
   }
   return $falg;
  }
 }
 
 //看一款目录检测并写文件函数
 
 function htm_w(
    $w_dir = '',
    $w_filename = '',
    $w_content = ''
   ){

  $dvs  = '';
  if($w_dir && $w_filename && $w_content){
   //目录检测数量
   $w_dir_ex  = explode('/',$w_dir);
   $w_new_dir = ''; //处理后的写入目录
   unset($dvs,$fdk,$fdv,$w_dir_len);
   foreach((array)$w_dir_ex as $dvs){
    if(trim($dvs) && $dvs!='..'){
     $w_dir_len .= '../';
     $w_new_dir .= $dvs.'/';
     if (!@is_dir($w_new_dir)) @mkdir($w_new_dir, 0777);
    }
   }


   //获得需要更改的目录数
   foreach((array)$this->filedir as $fdk=>$fdv){
    $w_content = str_replace($fdv,$w_dir_len.str_replace('../','',$fdv),$w_content);
   }
   $this->writer($w_dir.$w_filename,$w_content);
  }
 }
 ?>

本文章提供一款php目录管理程序,他可以对目录下的文件,文件夹,等各种文件进行管理删除操作,可以支持无限级目录的管理哦。
 代码如下 复制代码

include("class.php");
$path = $_get['path'];
if($path == ""){
 $path = "dir"; 
}else{
 if(!strstr($path,"dir")){
  $path = "dir/".$path;
 }else{
  $path = $path; 
 }
}

$newdir = new dirver();
$newdir -> setpath($path);
$newdir -> dirdata();
$files = $newdir -> getfiles();
$dirs = $newdir -> getdirs();
//print_r($files);
//print_r($dirs);

echo('<link href="style.css教程" rel="stylesheet" type="text/css" />');
$max = 3;
$j = 0;
if(count($dirs) == 2){
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
 print("<td width='33%'><img src='type/dir.png'/>");
 print('<a href="test.php?path='.$path."/".$dirs[0].'">');
 print($dirs[0]);
 print('</a>');
 print("</td>");
 print("<td width='33%'><img src='type/dir.png'/>");
 print('<a href="test.php?path='.$path."/".$dirs[1].'">');
 print($dirs[1]);
 print('</a>');
 print("</td>");
 print("<td width='33%'>");
 print("&nbsp;&nbsp;");
 print("</td>");
 echo '</tr></table>';
}else{
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
while($j <= (count($dirs) -1)){
 print("<td ><img src='type/dir.png'/>");
 print('<a href="test.php?path='.$path."/".$dirs[$j].'">');
 print($dirs[$j]);
 print('</a>');
 print("</td>");
 if(($j + 1) % $max == 0){
   echo '</tr>';
   if(($j + 1) != count($dirs)){
    echo '<tr>';
     }
  }
  $j++;
 }
 echo '</tr></table>';
}
$i = 0;
if(count($files) == 2){
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
 print("<td width='33%'><img src='type/".$newdir -> getfiletype($files[0]).".png'/>&nbsp;");
 print($newdir -> change2line($files[0]));
 print("</td>");
 print("<td width='33%'><img src='type/".$newdir -> getfiletype($files[1]).".png'/>&nbsp;");
 print($newdir -> change2line($files[1]));
 print("</td>");
 print("<td width='33%'>");
 print("&nbsp;&nbsp;");
 print("</td>");
 echo '</tr></table>';
}else{
echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
while($i <= (count($files) -1)){
 print("<td width=100><img src='type/".$newdir -> getfiletype($files[$i]).".png'/>&nbsp;");
 print($newdir -> change2line($files[$i])); 
 print("</td>");
 if(($i + 1) % 3 == 0){
   echo '</tr>';
   if(($i + 1) != count($files)){
    echo '<tr>';
    }
 }
 
 $i++;
}
 echo '</tr></table>';
}
?>


class.php

<?php
  class for php4.x
 class  dirver{
  /class var/
  var $path;
  var $flies;
  var $dirs;
  /
  function dirver(){
   $this -> path = ""; 
   $this -> files = array();
   $this -> dirs = array();
  }
  
  function dirdata(){
   if(isset($this -> path)){
    $handle = dir($this -> path);
    while(false !== ($data = $handle -> read())){
     if(is_dir($this -> connectname($this -> path,$data)) && $data != "." && $data != ".."){
       $this -> dirs[] = $data;
       continue;
      }
      
     if($data != "." && $data != ".." && is_file($this -> connectname($this -> path,$data))){
       $this -> files[] = $data;
       continue;
      }
     
    }
    $handle -> close(); 
   }else{
    return false; 
   }
  }
  
 function setpath($src){
   if($src != ""){
    $this -> path = $src; 
   }else{
    return false; 
   }
  }
 /
 function connectname($path,$name){
  return $path."/".$name;
 }
 /
 function change2line($name){
  $basename = explode(".",$name);
  $basename = $basename[0];
  $tmp = $this -> path."/".$name;
  $tmp = '<a href="'.$tmp.'" target="_blank">'.$basename.'</a>';
  return $tmp; 
 }
 
 function getfiletype($file){
  if($file != ""){
   $tmp = explode(".",$file);
   $type = $tmp[count($tmp)-1];
   return $type; 
  }
 }
 
 
 function getfiles(){
  return $this -> files;
  }
 
 function getdirs(){
  return $this -> dirs; 
  }
 //
 }

?>

/

 代码如下 复制代码

*  一、本程序基于div+css教程 新型架构php探针,免费开源的自由软件,功能强大,结构清晰,使用方便。
  1.支持windows,linux,unix,freebsd,sun solar系统
  2.支持ie6,ie7,firefox,google chrome等浏览器。
  
  二、主要用途及适用对象:
  1.熟悉php编程的业余爱好者及专业开发人员。
  2.机房管理人员配置linux(windows)+php+mysql教程+zend系统环境,检测系统是否配置成功。
  3.对于购买虚拟主机的用户,用于测试服务器性能。
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
 //////////////////以下两变量可以修改配制
 //如果这个探针你是用来验示的,你可以在下面变量中输入相关信息(会显示在页面底部
    header("content-type: text/html; charset=utf-8");
    error_reporting(e_error | e_warning | e_parse);
 ob_start();
    
    $valint = (false == empty($_post['pint']))?$_post['pint']:"未测试";
    $valfloat = (false == empty($_post['pfloat']))?$_post['pfloat']:"未测试";
    $valio = (false == empty($_post['pio']))?$_post['pio']:"未测试";
    $mysqlreshow = "none";
    $mailreshow = "none";
    $funreshow = "none";
    $opreshow = "none";
    $sysreshow = "none";
//============   定义常量 用于替换模板输出变量  =======================
  //define("yes", "<span class='resyes'>yes</span>");
  //define("no", "<span class='resno'>no</span>");
  define("yes", "<span class='resyes'>√</span>");
  define("no", "<span class='resno'>×</span>");

//=================================================================
    define("icon", "<span class='icon'>2</span>&nbsp;");
    $phps教程elf = $_server[php_self] ? $_server[php_self] : $_server[script_name];
    define("phpself", preg_replace("/(.{0,}?/+)/", "", $phpself));
    
    if ($_get['act'] == "phpinfo")
    {
        phpinfo();
        exit();
    }
    elseif($_post['act'] == "整型测试")
    {
        $valint = test_int();
    }
    elseif($_post['act'] == "浮点测试")
    {
        $valfloat = test_float();
    }
    elseif($_post['act'] == "io测试")
    {
        $valio = test_io();
    }
    elseif($_post['act'] == "connect")
    {
        $mysqlreshow = "show";
        $mysqlre = "mysql连接测试结果:";
        $mysqlre .= (false !== @mysql_connect($_post['mysqlhost'], $_post['mysqluser'], $_post['mysqlpassword']))?"mysql服务器连接正常, ":"mysql服务器连接失败, ";
        $mysqlre .= "数据库教程 <b>".$_post['mysqldb']."</b> ";
        $mysqlre .= (false != @mysql_select_db($_post['mysqldb']))?"连接正常":"连接失败";
    }
    elseif($_post['act'] == "sendmail")
    {
        $mailreshow = "show";
        $mailre = "mail邮件发送测试结果:发送";
        $mailre .= (false !== @mail($_post["mailreceiver"], "uenuprobe mail server test.", "this email is sent by uenuprobe. copyright uenucom http://www.uenu.com"))?"完成":"失败";
    }
    elseif($_post['act'] == "function_check")
    {
        $funreshow = "show";
        $funre = "函数 <b>".$_post['funname']."</b> 支持状况检测结果:".isfun($_post['funname']);
    }
    elseif($_post['act'] == "configuration_check")
    {
        $opreshow = "show";
        $opre = "配置参数 <b>".$_post['opname']."</b> 检测结果:".getcon($_post['opname']);
    }
 
//========================================================================

//========================================================================
   switch (php_os)
    {
        case "linux":
        $sysreshow = (false != ($sysinfo = sys_linux()))?"show":"none";
        break;
        case "freebsd":
        $sysreshow = (false != ($sysinfo = sys_freebsd()))?"show":"none";
        break;
  case "windows":
        //$sysreshow = (false != ($sysinfo = sys_windows()))?"show":"none";
  $sysinfo['uptime'] ="对不起windows系统不支持";
        break;
        default:
        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>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="common/control.css">
<script type="text/网页特效" language="javascript" src="common/admin.otable.js"></script>
<script type="text/javascript" language="javascript" src="common/include.func.js"></script>
<title>服务器信息</title>
<style type="text/css">
.resyes {
 font-size: 12px;
 color: #090;
 font-weight:bold;
 font-family: verdana;
}
.resno {
 font-size: 12px;
 color: #f00;
 font-weight:bold;
 font-family: verdana;
}
.check00{
 color: #630; 
}
</style>
<script type="text/javascript">
window.onload=function(){
 var otable=document.getelementbyid("otable");
 for(var i=0;i<otable.rows.length;i++){
  if(i%2==0) //偶数行时
   otable.rows[i].classname="altrow";
 }
 
 var otable2=document.getelementbyid("otable2");
 for(var i=0;i<otable2.rows.length;i++){
  if(i%2==0) //偶数行时
   otable2.rows[i].classname="altrow";
 }
 
 var otable3=document.getelementbyid("otable3");
 for(var i=0;i<otable3.rows.length;i++){
  if(i%2==0) //偶数行时
   otable3.rows[i].classname="altrow";
 }
 
 var otable4=document.getelementbyid("otable4");
 for(var i=0;i<otable4.rows.length;i++){
  if(i%2==0) //偶数行时
   otable4.rows[i].classname="altrow";
 }
 
 var otable5=document.getelementbyid("otable5");
 for(var i=0;i<otable5.rows.length;i++){
  if(i%2==0) //偶数行时
   otable5.rows[i].classname="altrow";
 }
}
</script>
</head>

<body class="contentbody">
<div class="maindiv">
<span class="ctitle">服务器信息</span>
<ul class="cmenu">
 <li><a href="server_info.php?action=">服务器特征</a></li>
 <li><a href="server_info.php?action=phpinfo">php基本特征</a></li>
 <li><a href="server_info.php?action=otherinfo">php组件支持状况</a></li>
 <li><a href="server_info.php?action=dbinfo">数据库支持状况</a></li>
 <li><a href="server_info.php?action=testinfo">性能检测</a></li>
    <li><a href="server_moreinfo.php">服务器详细信息</a></li>
</ul>

<div class="concontent">
<?php
switch($_get['action']){
 case '':
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="2" align="center">服务器特征</th>
</tr>
<tr>
 <td width="150">服务器时间</td>
    <td><?php echo gmdate("y年m月d日 h:i:s",time());?>&nbsp;(格林威治标准时间)&nbsp;&nbsp;<?php echo gmdate("y年n月j日 h:i:s",time()+8*3600)?>&nbsp;(北京时间)</td>
</tr>
<tr>
    <td>服务器域名</td>
    <td><?php echo("<a href="http://$_server[server_name]"  title=访问此域名 target=_blank>$_server[server_name]</a>"); ?></td>
</tr>
<tr>
 <td>服务器ip地址</td>
    <td><?php $host_ip=gethostbyname($_server["server_name"]); echo($host_ip);?></td>
</tr>
<tr>
 <td>服务器操作系统</td>
    <td><?php $os = explode(" ", php_uname()); echo $os[0]; echo "&nbsp;&nbsp;";
 if ($os[0] =="windows") {echo "主机名称:".$os[2];} else {echo "内核版本:".$os[2];}?></td>
</tr>
<tr>
 <td>服务器运行时间</td>
    <td><?php if ($sysinfo['uptime']!=""){ echo $sysinfo['uptime'];} else  echo "对不起windows系统不支持"; ?></td>
</tr>
<tr>
 <td>服务器操作系统文字编码</td>
    <td><?php echo($_server["http_accept_language"]); ?></td>
</tr>
<tr>
 <td>服务器解译引擎</td>
    <td><?php echo($_server["server_software"]); ?></td>
</tr>
<tr>
 <td>web服务端口</td>
    <td><?php echo($_server["server_port"]); ?></td>
</tr>
<tr>
 <td>服务器管理员</td>
    <td><a href="mailto:<?php echo $_server['server_admin'];?>"><?php echo $_server['server_admin'];?></a></td>
</tr>
<tr>
 <td>本文件路径</td>
    <td><?php echo($_server["script_filename"]);?></td>
</tr>
<tr>
 <td>服务端剩余空间</td>
    <td><?php echo intval(diskfreespace(".") / (1024 * 1024)).'mb';?></td>
</tr>
<tr>
 <td>系统当前用户名</td>
    <td><?php echo @get_current_user();?></td>
</tr>
</table>
<br />
<!-- 仅在windows 环境中输出-->
<?php if(("show" !==$sysreshow) & ("0"!= $_env["number_of_processors"])& (""!= $_env["number_of_processors"])){?>
<div class="info3">服务器处理器</div><div class="info4">cpu个数:<?php echo $_env["number_of_processors"]?> <?php echo "&nbsp;&nbsp;".$_env["processor_identifier"]; echo "&nbsp;&nbsp;运行级别:".$_env["processor_level"]; echo "&nbsp;&nbsp;版本:".$_env["processor_revision"];?></div>
<?php }?>
<!-- 仅在windows 环境中输出结束-->
<!-- linux or unix 参数输出-->
<?php if(("show"==$sysreshow)&("0" != $sysinfo['cpu']['num'])&("" != $sysinfo['cpu']['num'])){?>
<div class="info3">服务器处理器</div><div class="info4">cpu个数:<?php echo $sysinfo['cpu']['num']?> &nbsp;&nbsp;<?php echo $sysinfo['cpu']['detail']?></div>
<?php }?>
<?php if("show"==$sysreshow){?>
<div class="info3">内存使用状况</div><div class="info4">
<?php echo $sysinfo['memtotal']?>m, 已使用
<?php echo $sysinfo['memused']?>m, 空闲
<?php echo $sysinfo['memfree']?>m, 使用率
<?php echo $sysinfo['mempercent']?>%</div>
<div class="info3">swap区</div><div class="info4">
共<?php echo $sysinfo['swaptotal']?>m, 已使用
<?php echo $sysinfo['swapused']?>m, 空闲
<?php echo $sysinfo['swapfree']?>m, 使用率
<?php echo $sysinfo['swappercent']?>%</div>
<div class="info3">系统平均负载</div><div class="info4"><?php echo $sysinfo['loadavg']?></div>
<?php }?>
<!-- linux or unix 参数输出结束-->
<?php
  break;
 case 'phpinfo':
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="4" align="center">php基本特征</th>
</tr>
<tr>
 <td width="30%">php版本</td>
    <td width="20%"><?php echo php_version;?></td>
 <td width="30%">php运行方式</td>
    <td><?php /**strtoupper(php_sapi_name());**/ echo ucwords(php_sapi_name());?></td>
</tr>
<tr>
 <td>支持zend编译运行&nbsp;&nbsp;(<?php if($zend="yes") {echo "版本:";echo zend_version();}?>)</td>
    <td><?php echo $zend=(get_cfg_var("zend_optimizer.optimization_level")||get_cfg_var("zend_extension_manager.optimizer_ts")||get_cfg_var("zend_extension_ts")) ?yes:no?></td>
 <td>运行于安全模式</td>
    <td><?php if(get_cfg_var("safemode")){echo("是");}else echo("否"); ?></td>
</tr>
<tr>
 <td>自动定义全局变量&nbsp;register_globals</td>
    <td><?php echo @get_cfg_var("register_globals")?'on' : 'off';?></td>
 <td>允许使用url打开文件allow_url_fopen</td>
    <td><?php echo get_cfg_var("allow_url_fopen")=="1"?yes:no?></td>
</tr>
<tr>
 <td>允许动态加载链接库enable_dl</td>
    <td><?php echo get_cfg_var("enable_dl")=="1"?yes:no?></td>
 <td>显示错误信息&nbsp;display_errors</td>
    <td><?php echo get_cfg_var("display_errors")=="1"?yes:no?></td>
</tr>
<tr>
 <td>短标记&lt;? ?&gt;支持</td>
    <td><?php echo @get_cfg_var("short_open_tag")?yes:no;?></td>
 <td>标记&lt;% %&gt;支持</td>
    <td><?php echo @get_cfg_var("asp教程_tags")?yes:no;?></td>
</tr>
<tr>
 <td>cookie支持</td>
    <td><?php echo isset($http_cookie_vars)?yes:no;?></td>
 <td>session支持</td>
    <td><?php echo function_exists(session_start)?yes:no;?></td>
</tr>
<tr>
 <td>浮点运算有效数字显示位数</td>
    <td><?php echo @get_cfg_var("precision");?></td>
 <td>强制y2k兼容</td>
    <td><?php echo @get_cfg_var("y2k_compliance")?yes:no;?></td>
</tr>
<tr>
 <td>被禁用的函数disable_functions</td>
    <td><?php $disused = @get_cfg_var("disable_functions")?"1":"0";
if($disused =="1")
{echo '<a href="#" title="
'.@get_cfg_var("disable_functions").'
">'."more".'</a>';}
else {echo "none";}?></td>
 <td>程序最长运行时间max_execution_time</td>
    <td><?php echo(get_cfg_var("max_execution_time")."秒");?></td>
</tr>
<tr>
 <td>程序最多允许使用内存量 memory_limit</td>
    <td><?php echo @get_cfg_var("memory_limit");?></td>
 <td>post最大字节数&nbsp;post_max_size</td>
    <td><?php echo @get_cfg_var("post_max_size");?></td>
</tr>
<tr>
 <td>允许最大上传文件&nbsp;upload_max_filesize</td>
    <td><?php echo @get_cfg_var("file_uploads")?@get_cfg_var("upload_max_filesize") : $error;?></td>
 <td>php信息 phpinfo</td>
    <td><?php echo (false!==eregi("phpinfo",$disfuns))?no:"<a href='$phpself?act=phpinfo' target='_blank' class='static'>phpinfo</a>"?></td>
</tr>
<tr>
 <td>html错误显示</td>
    <td><?php echo @get_cfg_var("html_errors")?yes:no;?></td>
 <td>调试器地址/端口</td>
    <td><?php echo $debugerhost=@get_cfg_var("debugger.host")?yes:no;if ($debugerhost =="yes") {echo @get_cfg_var("debugger.port")?yes:no;}?></td>
</tr>
<tr>
 <td>smtp支持</td>
    <td><?php echo @get_cfg_var("smtp")?yes:no;?></td>
 <td>smtp地址</td>
    <td><?php echo @get_cfg_var("smtp");?></td>
</tr>
</table>
<?php
  break;
 case 'otherinfo': 
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="4" align="center">php组件支持状况</th>
</tr>
<tr>
 <td width="30%">拼写检查 aspell library</td>
    <td width="20%"><?php echo function_exists(aspell_new)?yes:no;?></td>
    <td width="30%">高精度数学运算 bcmath</td>
    <td><?php echo function_exists(bcadd)?yes:no;?></td>
</tr>
<tr>
 <td>历法运算 calendar</td>
    <td><?php echo function_exists(jdtofrench)?yes:no;?></td>
 <td>图形处理 gd library</td>
    <td><?php echo function_exists(imageline)?yes:no;?></td>
</tr>
<tr>
 <td>类/对象支持</td>
    <td><?php echo function_exists(class_exists)?yes:no;?></td>
 <td>字串类型检测支持</td>
    <td><?php echo function_exists(ctype_upper)?yes:no;?></td>
</tr>
<tr>
 <td>iconv编码支持</td>
    <td><?php echo function_exists(iconv)?yes:no;?></td>
 <td>mcrypt加密处理支持</td>
    <td><?php echo function_exists(mcrypt_cbc)?yes:no;?></td>
</tr>
<tr>
 <td>哈稀计算 mhash</td>
    <td><?php echo function_exists(mhash)?yes:no;?></td>
 <td>openssl支持</td>
    <td><?php echo function_exists(openssl_open)?yes:no;?></td>
</tr>
<tr>
 <td>prel相容语法 pcre</td>
    <td><?php echo function_exists(preg_match)?yes:no;?></td>
 <td>正则扩展(兼容perl)支持</td>
    <td><?php echo function_exists(preg_match)?yes:no;?></td>
</tr>
<tr>
 <td>socket支持</td>
    <td><?php echo function_exists(fsockopen)?yes:no;?></td>
 <td>流媒体支持</td>
    <td><?php echo function_exists(stream_context_create)?yes:no;?></td>
</tr>
<tr>
 <td>tokenizer支持</td>
    <td><?php echo function_exists(token_name)?yes:no;?></td>
 <td>url支持</td>
    <td><?php echo function_exists(parse_url)?yes:no;?></td>
</tr>
<tr>
 <td>wddx支持(web distributed data exchange)</td>
    <td><?php echo function_exists(wddx_add_vars)?yes:no;?></td>
 <td>压缩文件支持(zlib)</td>
    <td><?php echo function_exists(gzclose)?yes:no;?></td>
</tr>
<tr>
 <td>xml解析</td>
    <td><?php echo function_exists(xml_set_object)?yes:no;?></td>
 <td>ftp</td>
    <td><?php echo function_exists(ftp_login)?yes:no;?></td>
</tr>
<tr>
 <td>目录存取协议(ldap)支持</td>
    <td><?php echo function_exists(ldap_close)?yes:no;?></td>
 <td>yellow page系统支持</td>
    <td><?php echo function_exists(yp_match)?yes:no;?></td>
</tr>
<tr>
 <td>php和java综合支持</td>
    <td><?php echo function_exists(java_last_exception_get)?yes:no;?></td>
 <td>imap电子邮件系统支持</td>
    <td><?php echo function_exists(imap_close)?yes:no;?></td>
</tr>
<tr>
 <td>snmp网络管理协议支持</td>
    <td><?php echo function_exists(snmpget)?yes:no;?></td>
 <td>vmailmgr邮件处理支持</td>
    <td><?php echo function_exists(vm_adduser)?yes:no;?></td>
</tr>
<tr>
 <td>pdf文档支持</td>
    <td><?php echo function_exists(pdf_close)?yes:no;?></td>
 <td>fdf表单资料格式支持</td>
    <td><?php echo function_exists(fdf_close)?yes:no;?></td>
</tr>
</table>
<?php
  break;
 case 'dbinfo': 
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr>
 <th colspan="4" align="center">数据库支持状况</th>
</tr>
<tr>
 <td width="30%">mysql数据库支持</td>
    <td width="20%"><?php echo function_exists(mysql_close)?yes:no;?></td>
 <td width="30%">mysql数据库持续连接</td>
    <td><?php echo @get_cfg_var("mysql.allow_persistent")?yes:no;?></td>
</tr>
<tr>
 <td>mysql最大连接数</td>
    <td><?php echo @get_cfg_var("mysql.max_links")==-1 ? "不限" : @get_cfg_var("mysql.max_links");?></td>
 <td>odbc数据库连接</td>
    <td><?php echo function_exists(odbc_close)?yes:no;?></td>
</tr>
<tr>
 <td>sql server数据库支持</td>
    <td><?php echo function_exists(mssql_close)?yes:no;?></td>
 <td>msql数据库支持</td>
    <td><?php echo function_exists(msql_close)?yes:no;?></td>
</tr>
<tr>
 <td>postgre sql数据库支持</td>
    <td><?php echo function_exists(pg_close)?yes:no;?></td>
 <td>oracle数据库支持</td>
    <td><?php echo function_exists(ora_close)?yes:no;?></td>
</tr>
<tr>
 <td>oracle 8 数据库支持</td>
    <td><?php echo function_exists(ocilogoff)?yes:no;?></td>
 <td>dbase数据库支持</td>
    <td><?php echo function_exists(dbase_close)?yes:no;?></td>
</tr>
<tr>
 <td>sybase数据库支持</td>
    <td><?php echo function_exists(sybase_close)?yes:no;?></td>
 <td>dba数据库支持</td>
    <td><?php echo function_exists(dba_close)?yes:no;?></td>
</tr>
<tr>
 <td>dbm数据库支持</td>
    <td><?php echo function_exists(dbmclose)?yes:no;?></td>
 <td>dbx数据库支持</td>
    <td><?php echo function_exists(dbx_close)?yes:no;?></td>
</tr>
<tr>
 <td>db++数据库支持</td>
    <td><?php echo function_exists(dbplus_close)?yes:no;?></td>
 <td>frontbase数据库支持</td>
    <td><?php echo function_exists(fbsql_close)?yes:no;?></td>
</tr>
<tr>
 <td>filepro数据库支持</td>
    <td><?php echo function_exists(filepro)?yes:no;?></td>
 <td>informix数据库支持</td>
    <td><?php echo function_exists(ifx_close)?yes:no;?></td>
</tr>
<tr>
 <td>lotus notes数据库支持</td>
    <td><?php echo function_exists(notes_version)?yes:no;?></td>
 <td>interbase数据库支持</td>
    <td><?php echo function_exists(ibase_close)?yes:no;?></td>
</tr>
<tr>
 <td>ingres数据库支持</td>
    <td><?php echo function_exists(ingres_close)?yes:no;?></td>
 <td>hyperwave数据库支持</td>
    <td><?php echo function_exists(hw_close)?yes:no;?></td>
</tr>
<tr>
 <td>ovrimos sql数据库连接支持</td>
    <td><?php echo function_exists(ovrimos_close)?yes:no;?></td>
 <td>sesam数据库连接支持</td>
    <td><?php echo function_exists(sesam_disconnect)?yes:no;?></td>
</tr>
<tr>
 <td>sqlite数据库连接支持</td>
    <td><?php echo function_exists(sqlite_close)?yes:no;?></td>
 <td>adabas d数据库连接支持</td>
    <td><?php echo function_exists(ada_close)?yes:no;?></td>
</tr>
</table>
<?php
  break;
 case 'testinfo': 
?>
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo1"?>" method="post">
<!--服务器性能检测-->
<div id="testinfo1">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="ctable" id="otable" align="center">
<tr><th colspan="4">服务器性能检测</th></tr>
<tr align="center">
 <td width="25%">参照对象</td>
 <td width="25%">整数运算能力检测(1+1运算300万次)</td>
 <td width="25%">浮点运算能力检测(开平方300万次)</td>
 <td width="25%">数据i/o能力检测(读取10k文件1万次)</td>
</tr>
<tr align="center">
 <td>红色主机单线型(双核)</td>
 <td>0.33 秒</td>
 <td>0.95 秒</td>
 <td>0.03 秒</td>
</tr>
<tr align="center">
 <td>红色主机双线型(四核)</td>
 <td>0.25 秒</td>
 <td>0.79 秒</td>
 <td>0.03 秒</td>
</tr>
<tr align="center">
 <td>xeon(tm) 2.80*2+4g+centos 5.2</td>
 <td>0.068秒</td>
 <td>0.086秒</td>
 <td>小于0.100秒</td>
</tr>
<tr align="center">
 <td>xeon(tm) 2.80ghz+2g+freebsd 4.0</td>
 <td>0.501秒</td>
 <td>0.694秒</td>
 <td>小于0.100秒</td>
</tr>
<tr align="center" height="50">
 <td>本台服务器</td>
 <td><span style="color:#390"><?php echo $valint;?></span> <input type="submit" value="整型测试" name="act" class="button" /></td>
 <td><span style="color:#06c"><?php echo $valfloat;?></span> <input type="submit" value="浮点测试" name="act" class="button" /></td>
 <td><span style="color:#f60"><?php echo $valio;?></span> <input type="submit" value="io测试" name="act" class="button" /></td>
</tr>
</table>
</div>
<input type="hidden" name="pint" value="<?php echo $valint;?>" />
<input type="hidden" name="pfloat" value="<?php echo $valfloat;?>" />
<input type="hidden" name="pio" value="<?php echo $valio;?>" />
</form>
<?php
$ismysql = (false !== function_exists("mysql_query"))?"":" disabled";
$ismail = (false !== function_exists("mail"))?"":" disabled";
?>
<br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo2"?>" method="post">
<div id="testinfo2">
<!--mysql数据库连接检测--><br /><br />
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable2" align="center">
<tr><th colspan="2">mysql数据库连接检测</th></tr>
<tr>
 <td width="30%" align="right">mysql服务器:</td>
 <td><input name="mysqlhost" type="text" id="mysqlhost" value="localhost" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right">mysql用户名:</td>
 <td><input name="mysqluser" type="text" id="mysqluser" value="root" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right">mysql用户密码:</td>
 <td><input type="text" name="mysqlpassword" <?php echo $ismysql?> size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right">mysql数据库名称:</td>
 <td><input type="text" name="mysqldb" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right" height="30"><input type="submit" class="button" value="connect" <?php echo $ismysql?>  name="act" /></td>
    <td><div class="check00"><?php if("show"==$mysqlreshow){echo $mysqlre;}?> </div></td>
</tr>
</table>
</div>
</form>
<br /><br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo5"?>" method="post">
<div id="testinfo5">
<!--邮件发送检测-->
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable3" align="center">
<tr><th colspan="2">php配置参数状况</th></tr>
<tr>
    <td width="30%" align="right">请输入您要检测的参数名称:</td>
    <td><input type="text" name="opname" size="80" class="text2" /></td>
</tr>
<tr>
    <td align="right" height="30"><input type="submit" class="button" value="configuration_check" name="act" /></td>
    <td><div class="check00"><?php if("show"==$opreshow){echo $opre;}?></div></td>
</tr>
</table>
</div>
</form>
<br /><br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo3"?>" method="post">
<div id="testinfo3">
<!--函数检测-->
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable4" align="center">
<tr><th colspan="2">函数检测</th></tr>
<tr>
 <td width="30%" align="right">请输入您要检测的函数名称:</td>
 <td><input type="text" name="funname" size="80" class="text2" /></td>
</tr>
<tr>
 <td align="right" height="30"><input type="submit" class="button" value="function_check" name="act" /></td>
    <td><div class="check00"><?php if("show"==$funreshow){echo $funre;}?> </div></td>
</tr>
</table>
</div>
</form>
<br /><br />
<form action="<?php echo phpself."?action=testinfo&icon=$icon&#testinfo4"?>" method="post">
<div id="testinfo4">
<!--邮件发送检测-->
<table cellpadding="0" cellspacing="0" border="0" width="80%" class="ctable" id="otable5" align="center">
<tr><th colspan="2">mail邮件发送测试</th></tr>
<tr>
    <td width="30%" align="right">请输入您要检测的邮件地址:</td>
    <td><input type="text" name="mailreceiver" size="80" <?php echo $ismail?> class="text2" /></td>
</tr>
<tr>
    <td align="right" height="30"><input type="submit" class="button" value="sendmail" <?php echo $ismail?>  name="act" /></td>
    <td><div class="check00"><?php if("show"==$mailreshow){echo $mailre;}?></div></td>
</tr>
</table>
</div>
</form>

<?php
  break;
}?>
</div>

</div>
</body>
</html>
<?php

/*=============================================================
    函数库
=============================================================*/

/*-------------------------------------------------------------------------------------------------------------
    检测函数支持
--------------------------------------------------------------------------------------------------------------*/
    function isfun($funname)
    {
        return (false !== function_exists($funname))?yes:no;
    }
/*-------------------------------------------------------------------------------------------------------------
    检测php设置参数
--------------------------------------------------------------------------------------------------------------*/
    function getcon($varname)
    {
        switch($res = get_cfg_var($varname))
        {
            case 0:
            return no;
            break;
            case 1:
            return yes;
            break;
            default:
            return $res;
            break;
        }
        
    }
/*-------------------------------------------------------------------------------------------------------------
    整数运算能力测试
--------------------------------------------------------------------------------------------------------------*/
    function test_int()
    {
        $timestart = gettimeofday();
        for($i = 0; $i <= 3000000; $i++);
        {
            $t = 1+1;
        }
        $timeend = gettimeofday();
        $time = ($timeend["usec"]-$timestart["usec"])/1000000+$timeend["sec"]-$timestart["sec"];
        $time = round($time, 6)."秒";
        return $time;
    }
/*-------------------------------------------------------------------------------------------------------------
    浮点运算能力测试
--------------------------------------------------------------------------------------------------------------*/
    function test_float()
    {
        $t = pi();
        $timestart = gettimeofday();
        for($i = 0; $i < 3000000; $i++);
        {
            sqrt($t);
        }
        $timeend = gettimeofday();
        $time = ($timeend["usec"]-$timestart["usec"])/1000000+$timeend["sec"]-$timestart["sec"];
        $time = round($time, 6)."秒";
        return $time;
    }
/*-------------------------------------------------------------------------------------------------------------
    数据io能力测试
--------------------------------------------------------------------------------------------------------------*/
    function test_io()
    {
        $fp = @fopen(phpself, "r");
        $timestart = gettimeofday();
        for($i = 0; $i < 10000; $i++)
        {
            @fread($fp, 10240);
            @rewind($fp);
        }
        $timeend = gettimeofday();
        @fclose($fp);
        $time = ($timeend["usec"]-$timestart["usec"])/1000000+$timeend["sec"]-$timestart["sec"];
        $time = round($time, 6)."秒";
        return($time);
    }
/*-------------------------------------------------------------------------------------------------------------
    比例条
--------------------------------------------------------------------------------------------------------------*/
    function bar($percent)
    {
    echo '<br/><ul class="bar">
 <li style="width:';
 echo $percent."%">";
    echo '&nbsp;</li>
    </ul>';
}
/*-------------------------------------------------------------------------------------------------------------
    根据不同系统取得cpu相关信息
--------------------------------------------------------------------------------------------------------------*/
 switch(php_os) {
  case "linux":
   $sysreshow = (false !== ($sysinfo = sys_linux()))?"show":"none";
   break;
  case "freebsd":
   $sysreshow = (false !== ($sysinfo = sys_freebsd()))?"show":"none";
   break;
  case "winnt":
   $sysreshow = (false !== ($sysinfo = sys_windows()))?"show":"none";
   break;
  default:
   break;
 }

/*-------------------------------------------------------------------------------------------------------------
    系统参数探测 linux
--------------------------------------------------------------------------------------------------------------*/
    function sys_linux()
    {
        // cpu
        if (false === ($str = @file("/proc/cpuinfo"))) return false;
        $str = implode("", $str);
        @preg_match_all("/models+names{0,}:+s{0,}([ws)(.]+)[ ]+/", $str, $model);
        //@preg_match_all("/cpus+mhzs{0,}:+s{0,}([d.]+)[ ]+/", $str, $mhz);
        @preg_match_all("/caches+sizes{0,}:+s{0,}([d.]+s{0,}[a-z]+[ ]+)/", $str, $cache);
        if (false !== is_array($model[1]))
            {
            $res['cpu']['num'] = sizeof($model[1]);
            for($i = 0; $i < $res['cpu']['num']; $i++)
            {
                $res['cpu']['detail'][] = "类型:".$model[1][$i]." 缓存:".$cache[1][$i];
            }
            if (false !== is_array($res['cpu']['detail'])) $res['cpu']['detail'] = implode("<br />", $res['cpu']['detail']);
            }
        
        // uptime
        if (false === ($str = @file("/proc/uptime"))) return false;
        $str = explode(" ", implode("", $str));
        $str = trim($str[0]);
        $min = $str / 60;
        $hours = $min / 60;
        $days = floor($hours / 24);
        $hours = floor($hours - ($days * 24));
        $min = floor($min - ($days * 60 * 24) - ($hours * 60));
        if ($days != 0) {$res['uptime'] = $days."天";}
        if ($hours != 0) {$res['uptime'] .= $hours."小时";}
        $res['uptime'] .= $min."分钟";
        
        // memory
        if (false === ($str = @file("/proc/meminfo"))) return false;
        $str = implode("", $str);
        preg_match_all("/memtotals{0,}:+s{0,}([d.]+).+?memfrees{0,}:+s{0,}([d.]+).+?swaptotals{0,}:+s{0,}([d.]+).+?swapfrees{0,}:+s{0,}([d.]+)/s", $str, $buf);
        
        $res['memtotal'] = round($buf[1][0]/1024, 2);
        $res['memfree'] = round($buf[2][0]/1024, 2);
        $res['memused'] = ($res['memtotal']-$res['memfree']);
        $res['mempercent'] = (floatval($res['memtotal'])!=0)?round($res['memused']/$res['memtotal']*100,2):0;
        
        $res['swaptotal'] = round($buf[3][0]/1024, 2);
        $res['swapfree'] = round($buf[4][0]/1024, 2);
        $res['swapused'] = ($res['swaptotal']-$res['swapfree']);
        $res['swappercent'] = (floatval($res['swaptotal'])!=0)?round($res['swapused']/$res['swaptotal']*100,2):0;
        
        // load avg
        if (false === ($str = @file("/proc/loadavg"))) return false;
        $str = explode(" ", implode("", $str));
        $str = array_chunk($str, 3);
        $res['loadavg'] = implode(" ", $str[0]);
        
        return $res;
    }
/*-------------------------------------------------------------------------------------------------------------
    系统参数探测 freebsd
--------------------------------------------------------------------------------------------------------------*/
    function sys_freebsd()
    {
        //cpu
        if (false === ($res['cpu']['num'] = get_key("hw.ncpu"))) return false;
        $res['cpu']['detail'] = get_key("hw.model");
        
        //load avg
        if (false === ($res['loadavg'] = get_key("vm.loadavg"))) return false;
        $res['loadavg'] = str_replace("{", "", $res['loadavg']);
        $res['loadavg'] = str_replace("}", "", $res['loadavg']);
        
        //uptime
        if (false === ($buf = get_key("kern.boottime"))) return false;
        $buf = explode(' ', $buf);
        $sys_ticks = time() - intval($buf[3]);
        $min = $sys_ticks / 60;
        $hours = $min / 60;
        $days = floor($hours / 24);
        $hours = floor($hours - ($days * 24));
        $min = floor($min - ($days * 60 * 24) - ($hours * 60));
        if ($days != 0) $res['uptime'] = $days."天";
        if ($hours != 0) $res['uptime'] .= $hours."小时";
        $res['uptime'] .= $min."分钟";
        
        //memory
        if (false === ($buf = get_key("hw.physmem"))) return false;
        $res['memtotal'] = round($buf/1024/1024, 2);
        $buf = explode(" ", do_command("vmstat", ""));
        $buf = explode(" ", trim($buf[2]));
        
        $res['memfree'] = round($buf[5]/1024, 2);
        $res['memused'] = ($res['memtotal']-$res['memfree']);
        $res['mempercent'] = (floatval($res['memtotal'])!=0)?round($res['memused']/$res['memtotal']*100,2):0;
          
        $buf = explode(" ", do_command("swapinfo", "-k"));
        $buf = $buf[1];
        preg_match_all("/([0-9]+)s+([0-9]+)s+([0-9]+)/", $buf, $bufarr);
        $res['swaptotal'] = round($bufarr[1][0]/1024, 2);
        $res['swapused'] = round($bufarr[2][0]/1024, 2);
        $res['swapfree'] = round($bufarr[3][0]/1024, 2);
        $res['swappercent'] = (floatval($res['swaptotal'])!=0)?round($res['swapused']/$res['swaptotal']*100,2):0;
        
        return $res;
    }
    
/*-------------------------------------------------------------------------------------------------------------
    取得参数值 freebsd
--------------------------------------------------------------------------------------------------------------*/
function get_key($keyname)
    {
        return do_command('sysctl', "-n $keyname");
    }
    
/*-------------------------------------------------------------------------------------------------------------
    确定执行文件位置 freebsd
--------------------------------------------------------------------------------------------------------------*/
    function find_command($commandname)
    {
        $path = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
        foreach($path as $p)
        {
            if (@is_executable("$p/$commandname")) return "$p/$commandname";
        }
        return false;
    }
    
/*-------------------------------------------------------------------------------------------------------------
    执行系统命令 freebsd
--------------------------------------------------------------------------------------------------------------*/
    function do_command($commandname, $args)
    {
        $buffer = "";
        if (false === ($command = find_command($commandname))) return false;
        if ($fp = @popen("$command $args", 'r'))
            {
    while (!@feof($fp))
    {
     $buffer .= @fgets($fp, 4096);
    }
    return trim($buffer);
   }
        return false;
    }

/*-------------------------------------------------------------------------------------------------------------
    系统参数探测 windows
--------------------------------------------------------------------------------------------------------------*/
    function sys_windows()
 {
 //$phpos=php_os;
 $sysinfo['uptime'] ="对不起windows系统不支持";
 
 }
?>

天气预报信息采集自中央气象台,信息准确,覆盖面广,代码简单。返回是json代码,可以用于客户端调用,也可以在服务器端处理后显示,笔者的wordpress天气预报插件就是使用的这段代码哦。需要注意的是,这段代码会在服务器产生缓存文件,需要在当前目录中新建data文件夹,保证文件夹可写

    

 代码如下 复制代码

作者:    freemouse
     主页:    www.cnphp.info
     接口demo: http://www.cnphp.info/tianqi
     用法: 可以直接调用上面的地址会显示当地的天气信息,也可以这样用
    http://www.cnphp.info/tianqi/?q=江苏省南京市
    **/

    $p = $_get['q'];
    $k = 0;
    $encoding = mb_detect_encoding($p);
    if($encoding != "utf-8"){
        $p = mb_convert_encoding($p,"utf-8","gbk");
    }
    $p_arr = array(
       "01" => "北京",
      "02" => "上海",
      "03" => "天津",
      "04" => "重庆",
      "05" => "黑龙江",
      "06" => "吉林",
      "07" => "辽宁",
      "08" => "内蒙古",
      "09" => "河北",
      "10" => "山西",
      "11" => "陕西",
      "12" => "山东",
      "13" => "新疆",
      "14" => "西藏",
      "15" => "青海",
      "16" => "甘肃",
      "17" => "宁夏",
      "18" => "河南",
      "19" => "江苏",
      "20" => "湖北",
      "21" => "浙江",
      "22" => "安徽",
      "23" => "福建",
      "24" => "江西",
      "25" => "湖南",
      "26" => "贵州",
      "27" => "四川",
      "28" => "广东",
      "29" => "云南",
      "30" => "广西",
      "31" => "海南",
      "32" => "香港",
      "33" => "澳门",
      "34" => "台湾"
    );
 
    function find(&$item,$key,$data){
        global $k;
        if(preg_match("/$item/u",$data)){
           $k = $key;
        }
    }
 
    function get_data_arr($key){
        if(!file_exists("./data/city{$key}.xml")){
            $c =file_get_contents( "http://m.weather.com.cn/data5/city{$key}.xml" );
            file_put_contents("./data/city{$key}.xml",$c);
        }
        else{
            $c = file_get_contents("./data/city{$key}.xml");
        }
       $arr = explode(",",$c);
       foreach($arr as $v){
           $data = explode("|",$v);
           $ret[$data[0]] = $data[1];
       }
       return $ret;
    }
 
    array_walk($p_arr,'find',$p);
    array_walk(get_data_arr($k),'find',$p);
    array_walk(get_data_arr($k),'find',$p);
    $ccode = get_data_arr($k);
    echo file_get_contents("http://m.weather.com.cn/data/{$ccode[$k]}.html");

[!--infotagslink--]

相关文章

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

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

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

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • JS实现自定义简单网页软键盘效果代码

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • jquery实现的伪分页效果代码

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

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • PHP实现清除wordpress里恶意代码

    公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
  • JS实现双击屏幕滚动效果代码

    本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
  • js识别uc浏览器的代码

    其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP开发微信支付的代码分享

    微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
  • vue.js 表格分页ajax 异步加载数据

    Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20
  • PHP常用的小程序代码段

    本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
  • php怎么用拼音 简单的php中文转拼音的实现代码

    小编分享了一段简单的php中文转拼音的实现代码,代码简单易懂,适合初学php的同学参考学习。 代码如下 复制代码 <?phpfunction Pinyin($_String...2017-07-06
  • php导出csv格式数据并将数字转换成文本的思路以及代码分享

    php导出csv格式数据实现:先定义一个字符串 存储内容,例如 $exportdata = '规则111,规则222,审222,规222,服2222,规则1,规则2,规则3,匹配字符,设置时间,有效期'."/n";然后对需要保存csv的数组进行foreach循环,例如复制代...2014-06-07
  • ecshop商品无限级分类代码

    ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25