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 相关文章推荐
我常用的几个类
Oct 09 PHP
web方式ftp
Oct 09 PHP
dedecms中常见问题修改方法总结
Mar 21 PHP
rrmdir php中递归删除目录及目录下的文件
May 15 PHP
浅析PHP绘图技术
Jul 03 PHP
PHP取整函数:ceil,floor,round,intval的区别详细解析
Aug 31 PHP
ThinkPHP行为扩展Behavior应用实例详解
Jul 22 PHP
php中switch语句用法详解
Aug 17 PHP
简介PHP的Yii框架中缓存的一些高级用法
Mar 29 PHP
浅析Yii2 gridview实现批量删除教程
Apr 22 PHP
ThinkPHP实现附件上传功能
Apr 27 PHP
php微信公众号开发之校园图书馆
Oct 20 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 substr,mb_substr以及mb_strcut的区别和用法
2013/06/21 PHP
php判断文件上传图片格式的实例详解
2017/09/30 PHP
PHP基于双向链表与排序操作实现的会员排名功能示例
2017/12/26 PHP
Thinkphp5框架简单实现钩子(Hook)行为的方法示例
2019/09/03 PHP
Laravel基础-关于引入公共文件的两种方式
2019/10/18 PHP
JS类定义原型方法的两种实现的区别评论很多
2007/09/12 Javascript
基于jquery的一个图片hover的插件
2010/04/24 Javascript
Three.js源码阅读笔记(基础的核心Core对象)
2012/12/27 Javascript
微信小程序 icon组件详细及实例代码
2016/10/25 Javascript
JS根据生日月份和日期计算星座的简单实现方法
2016/11/24 Javascript
百度地图JavascriptApi Marker平滑移动及车头指向行径方向
2017/03/13 Javascript
基于js 本地存储(详解)
2017/08/16 Javascript
JS排序算法之希尔排序与快速排序实现方法
2017/12/12 Javascript
原生JS+HTML5实现的可调节写字板功能示例
2018/08/30 Javascript
浅谈Webpack多页应用HMR卡住问题
2019/04/24 Javascript
微信小程序之左右布局的实现代码
2019/12/13 Javascript
Vue.js的模板语法详解
2020/02/16 Javascript
[02:32]【DOTA2亚洲邀请赛】iceice,梦开始的地方
2017/03/13 DOTA
[57:37]EG vs Mineski 2018国际邀请赛小组赛BO2 第二场 8.16
2018/08/17 DOTA
使用Django的模版来配合字符串翻译工作
2015/07/27 Python
详解Python 2.6 升级至 Python 2.7 的实践心得
2017/04/27 Python
Python使用pymongo模块操作MongoDB的方法示例
2018/07/20 Python
对Tensorflow中的变量初始化函数详解
2018/07/27 Python
Python发展史及网络爬虫
2019/06/19 Python
python中的逆序遍历实例
2019/12/25 Python
在python3中实现查找数组中最接近与某值的元素操作
2020/02/29 Python
python 实现弹球游戏的示例代码
2020/11/17 Python
意大利在线药房:Farmacia Loreto Gallo
2019/08/09 全球购物
weblogic面试题
2016/03/07 面试题
一套软件开发工程师笔试题
2015/05/18 面试题
String s = new String(“xyz”);创建了几个String Object?
2015/08/05 面试题
应聘自荐书
2013/10/08 职场文书
销售文员岗位职责
2013/11/29 职场文书
学年自我鉴定
2014/01/16 职场文书
小学生期末评语大全
2014/04/21 职场文书
小学四年级班主任工作经验交流材料
2015/11/02 职场文书