PHP自动生成月历代码


Posted in PHP onOctober 09, 2006

<?php
/* 
Function Written by Nelson Neoh @3/2004. 
For those who wants to utilize this code, please do not remove this remark. 
If you have done any enhancement to this code, please post the copy at http://www.dev-club.com PHP board.  Thank you.

Function usage: calendar(Month,Year)
*/

function calendar($MM,$YYYY){
    if($MM=="") $MM = date("m");
    if($YYYY=="") $YYYY = date("Y");
    if(checkdate($MM,1,$YYYY)){
        $stringDate = strftime("%d %b %Y",mktime (0,0,0,$MM,1,$YYYY));
        $days = strftime("%d",mktime (0,0,0,$MM+1,0,$YYYY));
        $firstDay = strftime("%w",mktime (0,0,0,$MM,1,$YYYY));
        $lastDay = strftime("%w",mktime (0,0,0,$MM,$days,$YYYY));
        $printDays = $days;
        $preMonth = strftime("%m",mktime (0,0,0,$MM-1,1,$YYYY));
        $preYear = strftime("%Y",mktime (0,0,0,$MM-1,1,$YYYY));
        $nextMonth = strftime("%m",mktime (0,0,0,$MM+1,1,$YYYY));
        $nextYear = strftime("%Y",mktime (0,0,0,$MM+1,1,$YYYY));
        print("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\">");
        print("<tr><th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$preMonth."&YY=".$preYear."\">P</a></th>");
        print("<th colspan=\"5\" valign=\"top\">".strftime("%b %Y",mktime (0,0,0,$MM,1,$YYYY))."</th>");
        print("<th valign=\"top\"><a href=\"".$_SERVER['PHP_SELF']."?NB=".$_GET["NB"]."&MM=".$nextMonth."&YY=".$nextYear."\">N</a></th></tr>");
        print("<tr style=\"font-family: Verdana; font-size:x-small\">");
        print("<th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>");

        $currentDays = 1;
        for($a=1;$a<=5;$a++){
            print("<tr align=\"left\" valign=\"top\" style=\"font-family: Verdana; font-size:x-small\">");
            $diffDays = $firstDay-$lastDay;
            if($firstDay>$lastDay && $currentDays ==1 && ($diffDays<>1)){
                for($x=$lastDay;$x>=0;$x--){
                    $printDays = $days-$x;
                    print("<td>$printDays</td>");
                }
                for($z=1;$z<$firstDay-$lastDay;$z++){
                    print("<td> </td>");
                }
                for($y=$firstDay;$y<7;$y++){
                    print("<td>$currentDays</td>");
                    $currentDays++;
                }
            } elseif($firstDay!=0 && $currentDays==1){
                for($z=1;$z<=$firstDay;$z++){
                    print("<td> </td>");
                }
                for($y=$firstDay;$y<7;$y++){
                    print("<td>$currentDays</td>");
                    $currentDays++;
                }
            } else {
                for($u=1;$u<=7 && $currentDays<=$days;$u++){
                    print("<td>$currentDays</td>");
                    $currentDays++;
                }
            }
            print("</tr>");
        }
        print("</table>");
    }
}
?>

 

PHP 相关文章推荐
生成静态页面的PHP类
Jul 15 PHP
PHP在XP下IIS和Apache2服务器上的安装
Sep 05 PHP
用PHP函数解决SQL injection
Oct 09 PHP
用php和MySql来与ODBC数据连接
Oct 09 PHP
使用bcompiler对PHP文件进行加密的代码
Aug 29 PHP
PHP 提取图片img标记中的任意属性的简单实例
Dec 10 PHP
php分页示例分享
Apr 30 PHP
php可应用于面包屑导航的递归寻找家谱树实现方法
Feb 02 PHP
php curl 获取https请求的2种方法
Apr 27 PHP
php实现在新浪云中使用imagick生成缩略图并上传的方法
Sep 26 PHP
php使用函数pathinfo()、parse_url()和basename()解析URL
Nov 25 PHP
php strftime函数的详细用法
Jun 21 PHP
十天学会php(3)
Oct 09 #PHP
十天学会php(1)
Oct 09 #PHP
十天学会php(2)
Oct 09 #PHP
论坛头像随机变换代码
Oct 09 #PHP
PHP中路径问题的解决方案
Oct 09 #PHP
新浪新闻小偷
Oct 09 #PHP
如何使用PHP获取网络上文件
Oct 09 #PHP
You might like
PHP中的串行化变量和序列化对象
2006/09/05 PHP
PHP 将图片按创建时间进行分类存储的实现代码
2010/01/05 PHP
解析PHP中DIRECTORY_SEPARATOR,PATH_SEPARATOR两个常量的作用
2013/06/21 PHP
php实现删除空目录的方法
2015/03/16 PHP
PHP利用hash冲突漏洞进行DDoS攻击的方法分析
2015/03/26 PHP
button没写type=button会导致点击时提交
2014/03/06 Javascript
BootStrap和jQuery相结合实现可编辑表格
2016/04/21 Javascript
详解JavaScript跨域总结与解决办法
2016/10/31 Javascript
JS及JQuery对Html内容编码,Html转义
2017/02/17 Javascript
JS实现的点击表头排序功能示例
2017/03/27 Javascript
Ionic3 UI组件之autocomplete详解
2017/06/08 Javascript
JS获取填报扩展单元格控件的值的解决办法
2017/07/14 Javascript
node中的session的具体使用
2018/09/14 Javascript
Vue.js组件间通信方式总结【推荐】
2018/11/23 Javascript
vue-cli项目使用mock数据的方法(借助express)
2019/04/15 Javascript
[54:18]DOTA2-DPC中国联赛 正赛 PSG.LGD vs LBZS BO3 第一场 1月22日
2021/03/11 DOTA
python练习程序批量修改文件名
2014/01/16 Python
Python2.7简单连接与操作MySQL的方法
2016/04/27 Python
Python获取文件所在目录和文件名的方法
2017/01/12 Python
python 统计一个列表当中的每一个元素出现了多少次的方法
2018/11/14 Python
Python3标准库glob文件名模式匹配的问题
2020/03/13 Python
澳大利亚领先的运动鞋商店:Hype DC
2018/03/31 全球购物
Opodo意大利:欧洲市场上领先的在线旅行社
2019/10/24 全球购物
广州足迹信息技术有限公司Java软件工程师试题
2014/02/15 面试题
工作个人的自我评价
2014/01/14 职场文书
《草虫的村落》教学反思
2014/02/16 职场文书
建筑专业毕业生自荐信
2014/05/25 职场文书
党员民主生活会材料
2014/12/15 职场文书
通报表扬范文
2015/01/17 职场文书
骨干教师个人总结
2015/02/11 职场文书
小学生暑假安全公约
2015/07/14 职场文书
协议书格式模板
2016/03/24 职场文书
PHP策略模式写法
2021/04/01 PHP
Node-Red实现MySQL数据库连接的方法
2021/08/07 MySQL
WebRTC记录音视频流(web技术分享)
2022/02/24 Javascript
java中为什么说子类的构造方法默认访问的是父类的无参构造方法
2022/04/13 Java/Android