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读MYSQL中文乱码的解决方法
Dec 17 PHP
php中将数组存到文件里的实现代码
Jan 19 PHP
php中的比较运算符详解
Oct 28 PHP
php中try catch捕获异常实例详解
Nov 21 PHP
thinkphp循环结构用法实例
Nov 24 PHP
PHP使用逆波兰式计算工资的方法
Jul 29 PHP
windows下的WAMP环境搭建图文教程(推荐)
Jul 27 PHP
PHP实现找出链表中环的入口节点
Jan 16 PHP
Laravel重定向,a链接跳转,控制器跳转示例
Oct 22 PHP
php pdo连接数据库操作示例
Nov 18 PHP
php+mysql实现的无限分类方法类定义与使用示例
May 27 PHP
PHPstorm启用自动换行的方法详解(IDE)
Sep 17 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/10/09 PHP
php对mongodb的扩展(初出茅庐)
2012/11/11 PHP
zend framework文件上传功能实例代码
2013/12/25 PHP
thinkPHP5.0框架URL访问方法详解
2017/03/18 PHP
使用PHP连接数据库_实现用户数据的增删改查的整体操作示例
2017/09/01 PHP
vmware linux系统安装最新的php7图解
2019/04/14 PHP
php解压缩zip和rar压缩包文件的方法
2019/07/10 PHP
php+js实现点赞功能的示例详解
2020/08/07 PHP
js直接编辑当前cookie的脚本
2008/09/14 Javascript
jQuery模拟原生态App上拉刷新下拉加载更多页面及原理
2015/08/10 Javascript
如何用angularjs制作一个完整的表格
2016/01/21 Javascript
教你用javascript实现随机标签云效果_附代码
2016/03/16 Javascript
JavaScript实现简单动态进度条效果
2018/04/06 Javascript
微信小程序实现滑动切换自定义页码的方法分析
2018/12/29 Javascript
如何通过setTimeout理解JS运行机制详解
2019/03/23 Javascript
微信小程序如何实现在线客服功能
2019/10/16 Javascript
Python 中 Meta Classes详解
2016/02/13 Python
利用Python命令行传递实例化对象的方法
2016/11/02 Python
Python之日期与时间处理模块(date和datetime)
2017/02/16 Python
Python 处理图片像素点的实例
2019/01/08 Python
微信公众号token验证失败解决方案
2019/07/22 Python
python自动化测试之DDT数据驱动的实现代码
2019/07/23 Python
Python学习笔记之Break和Continue用法分析
2019/08/14 Python
使用tensorflow DataSet实现高效加载变长文本输入
2020/01/20 Python
美国知名户外用品畅销中心:Sierra Trading Post
2016/07/19 全球购物
台湾母婴用品购物网站:Infant婴之房
2018/06/15 全球购物
eBay美国官网:eBay.com
2020/10/24 全球购物
如何在C# winform中异步调用web services
2015/09/21 面试题
夜大毕业生自我评价分享
2013/11/10 职场文书
幼儿园家长会欢迎词
2014/01/09 职场文书
大学生咖啡店创业计划书
2014/01/21 职场文书
2016春季校长开学典礼致辞
2015/11/26 职场文书
导游词之蜀山胜景瓦屋山
2019/11/29 职场文书
python 定义函数 返回值只取其中一个的实现
2021/05/21 Python
Python中的matplotlib绘制百分比堆叠柱状图,并为每一个类别设置不同的填充图案
2022/04/20 Python
微信小程序实现轮播图指示器
2022/06/25 Javascript