当前位置: 首页 > 图文教程 > 网络编程 > PHP > 用 php 编写的日历

PHP
PHP实例教程:Output Control输出函数
memcached和mysql主从环境下PHP开发
基于LAMP架构设计的WEB框架
PHP代码:验证IPV6地址是否合法的正则
PHP环境快读搭建绿色软件包PHPnow
PHP教程:$_SERVER的详细参数整理
php获取url字符串截取路径的文件名和扩展名的函数
在命令行下运行PHP脚本[带参数]的方法
PHP 实用代码收集
PHP 时间转换Unix时间戳代码
关于php fread()使用技巧
PHPMailer 中文使用说明小结
php addslashes和mysql_real_escape_string
php cout<<的一点看法
PHP 变量的定义方法
php学习之 认清变量的作用范围
php 静态变量与自定义常量的使用方法
认识并使用PHP超级全局变量
通过具体程序来理解PHP里面的抽象类
php读取xml实例代码

PHP 中的 用 php 编写的日历


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 66 ::
收藏到网摘: n/a


网上有很多JavaScript编写的日历,这种日历读取的是本地的时间,可能会不准确。所以想找一个用php编写的,能读取服务器时间的日历,但是一直都找不到合适的,于是我自己尝试着写了一个。 代码拷贝框
<?php $mnow=(isset($HTTP_GET_VARS['month']) && intval($HTTP_GET_VARS['month'])>0 && intval($HTTP_GET_VARS['month'])<13)?intval($HTTP_GET_VARS['month']):date("m"); $ynow=(isset($HTTP_GET_VARS['year']) && intval($HTTP_GET_VARS['year'])>1969 && intval($HTTP_GET_VARS['year'])<2038)?intval($HTTP_GET_VARS['year']):date("Y"); $mtime=mktime(0,0,0,$mnow,date("d"),$ynow); $f=date("w",mktime(0,0,0,$mnow,1,$ynow))-1; echo "<table id=\"calendar\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">"; echo "<tr><td colspan=\"4\" align=\"center\" class=\"calendartitle\"><a href=\"?".($mnow!=date("m")?"month=".intval($mnow)."&":"")."year=".(intval($ynow)==1970?"1970":intval($ynow)-1)."\"><</a>".$ynow."<a href=\"?".($mnow!=date("m")?"month=".intval($mnow)."&":"")."year=".(intval($ynow)==2037?"2037":intval($ynow)+1)."\">></a></td><td colspan=\"3\" align=\"center\" class=\"calendartitle\"><a href=\"?month=".(intval($mnow)==1?"12":intval($mnow)-1).($ynow!=date("Y")?"&year=".intval($ynow):"")."\"><</a>".date("M",$mtime)."<a href=\"?month=".(intval($mnow)==12?"1":intval($mnow)+1).($ynow!=date("Y")?"&year=".intval($ynow):"")."\">></a></td></tr>"; echo "<tr><td class=\"calendartop\">S</td><td class=\"calendartop\">M</td><td class=\"calendartop\">T</td><td class=\"calendartop\">W</td><td class=\"calendartop\">T</td><td class=\"calendartop\">F</td><td class=\"calendartop\">S</td></tr>"; for($i=0;$i<date("t",$mtime)+$f+1;$i++){ if($i%7==0)echo "<tr>"; echo "<td".(($i-$f==intval(date("d")) && $mnow==date("m") && $ynow==date("Y"))?" id=\"calendartoday\"":"").(($i%7==0
$i%7==6)?" class=\"calendarw\"":"").">"; if($i>$f)echo $i-$f; echo "</td>"; if($i%7==6)echo "</tr>"; } if($i%7<6 && $i%7>0)echo "<td colspan=\"".(7-$i%7)."\"></td></tr>"; if($i%7==6)echo "<td></td></tr>"; echo "</table>"; ?>
[Ctrl+A 全部选择 然后拷贝]