//调用 方法
?>
//调用 方法
?>
class multipage {
var $total;
var $perpage;
var $pages;
var $maxpage;
var $offset = 9;
var $curr_page;
function init($total, $perpage, $maxpage) { //初始化页数
$this->total;
$this->perpage;
$this->maxpage;
$this->offset = 9;
}
function getpagelist() {//获取分页列表
$result_pages = "";
$this->pages = ceil($this->total / $this->perpage);
if ($this->pages > $this->maxpage) {
$from = $this->curr_page - $this->offset;
if ($from < 1) {
$from = 1;
}
$to = $from + $this->maxpage - 1;
if ($to > $this->pages) {
$to = $this->pages;
if (($to - $from) < $this->maxpage) {
$from = $from - 1;
}
}
} else {
$from = 1;
$to = $this->pages;
}
$p = 0;
for($i = $from; $i <= $to; $i++) {
$result_pages[$p] = $i;
$p++;
}
return $result_pages;
}
function getfirst() { //获取第一页
if ($this->curr_page > 1 && $this->pages > 1) {
return 1;
} else {
return "";
}
}
function getlast() { //取末页
if ($this->pages > 1 && $this->curr_page < $this->pages) {
return $this->pages;
} else {
return "";
}
}
function getprev() {//上一页
$prevpage = $this->curr_page - 1;
if ($prevpage > 0) {
return $prevpage;
} else {
$prevpage = "";
return $prevpage;
}
}
function getnext() {//下一页
$nextpage = $this->curr_page + 1;
if ($nextpage <= $this->pages) {
return $nextpage;
} else {
$nextpage = "";
return $nextpage;
}
}
function gettotal() {//共多少页
if ($this->pages > 0) {
return $this->pages;
} else {
return 1;
}
}
}
session_start();
/* get post */
if (!function_exists("getpost")){function getpost(){if(count($_post)){foreach($_post as $key => $value){global ${$key};${$key}=$value;}}}}
方法二
方法一date函数
//2010-08-29 11:25:26
得到目前的日期和时间-我们有多少种方式?
2、 改变日期显示的方式-日期和时间的显示形式
3、 转换现在的日期为unix的时间戳值
4、 改变日期
a. 增加时间
b. 减去时间
c. 找出两日期之间的间隔
5、 为php教程添加dateadd函数
6、 为php添加datediff函数
php filesystem 函数
rename() 函数重命名文件或目录。
若成功,则该函数返回 true。若失败,则返回 false。
rename(oldname,newname,context)
参数
描述
oldname
必需。规定要重命名的文件或目录。
newname
必需。规定文件或目录的新名称。
context
必需。规定文件句柄的环境。context 是可修改流的行为的一套选项。
注释:在 php 4.3.3 之前,rename() 不能在基于 *nix 的系统中跨磁盘分区重命名文件。
注释:用于 oldname 中的封装协议必须和用于 newname 中的相匹配。
注释:对 context 的支持是 php 5.0.0 添加的。
<?php
rename("images","pictures");
?>
oldpath ----文件或目录原来路径
$newpath ----新定义路径
那么 rename($oldpath,$newpath)就可以完成文件/目录移动的操作
经过我的测试,win32和unix的php4版本都支持这个功能。
另外,好象php4的win32版取消了unlink()函数。那么还可以巧用rename()函数来完成删除的操作,例如:
$path ---- 文件或目录路径
$tmp ---- tmp目录(/tmp)
用rename($path,$tmp) 将文件移动到tmp目录.
empty 判断一个变量是否为“空”,isset 判断一个变量是否已经设置。正是这种所谓的“顾名思义”,令我开始时走了些弯路:当一个变量值等于0时,empty()也会成立(true),因而会发生一些意外。原来,empty 和 isset 虽然都是变量处理函数,它们都用来判断变量是否已经配置,它们却是有一定的区别:empty还会检测变量是否为空、为零。当一个变量值为0,empty 认为这个变量同等于空,即相当于没有设置。
比如检测 $id 变量,当 $id=0 时,用empty 和 isset 来检测变量 $id 是否已经配置,两都将返回不同的值—— empty 认为没有配置,isset 能够取得 $id 的值:
<script language="网页特效">
function startrequestusingpost() {
if(checktitle()==false)
{
return;
}
var title = document.getelementbyid("title").value;
createxmlhttprequest();
xmlhttp.open("post","checkntype",true);
xmlhttp.onreadystatechange = processresponse;
xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded");
xmlhttp.send("title=" + title);
}
function processresponse() {
if(xmlhttp.readystate == 4) {
if(xmlhttp.status == 200) {
var result = xmlhttp.responsetext;
if(result==1){
document.getelementbyid("message").style.display="inline";
document.getelementbyid("btnadd").disabled="disabled";
}else
{
document.getelementbyid("message").style.display="none";
document.getelementbyid("btnadd").disabled="";
}
}
}
}
function checktitle()
{
var title=document.getelementbyid("title").value;
if(title=="")
{
document.getelementbyid("lbltitle").style.display="inline";
return false;
}else
{
document.getelementbyid("lbltitle").style.display="none";
return true;
}
}
function delsame(&$array)
{
$i = 0;
while(isset($array[$i]))
{
$j = $i + 1;
while(isset($array[$j]))
{
if($array[$i] == $array[$j]) //如果发现后面有重复的元素
{
delmember($array, $j); //把它删除
$j--; //重新检查补上来的元素是否是重复的
}
$j ++;
}
$i ++;
}
}
//php遍历多维数组
//实例三,遍历二维数组
$a=array("red", "green", "blue", "yellow");
count($a); //得到4
unset($a[1]); //删除第二个元素
count($a); //得到3
echo $a[2]; //数组中仅有三个元素,本想得到最后一个元素,但却得到blue,
echo $a[1]; //无值