PHP生成月历代码


Posted in PHP onJune 14, 2007

<?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 相关文章推荐
PHP4引用文件语句的对比
Oct 09 PHP
IIS6.0中配置php服务全过程解析
Aug 07 PHP
php-fpm配置详解
Feb 12 PHP
php写的AES加密解密类分享
Jun 20 PHP
PHP中require和include路径问题详解
Dec 25 PHP
php输出全球各个时区列表的方法
Mar 31 PHP
php设置页面超时时间解决方法
Sep 22 PHP
PHP实现模拟http请求的方法分析
Dec 20 PHP
PHP自定义序列化接口Serializable用法分析
Dec 29 PHP
PHP设计模式之状态模式定义与用法详解
Apr 02 PHP
Laravel 登录后清空COOKIE的操作方法
Oct 14 PHP
PHP语言对接抖音快手小红书视频/图片去水印API接口源码
Aug 11 PHP
用PHP实现图象锐化代码
Jun 14 #PHP
PHP静态新闻列表自动生成代码
Jun 14 #PHP
discuz安全提问算法
Jun 06 #PHP
PHP5.2下chunk_split()函数整数溢出漏洞 分析
Jun 06 #PHP
phpMyAdmin下载、安装和使用入门教程
May 31 #PHP
测试您的 PHP 水平的题目
May 30 #PHP
Discuz板块横排显示图片的实现方法
May 28 #PHP
You might like
PHP安装全攻略:APACHE
2006/10/09 PHP
关于php正则匹配汉字的方法介绍
2013/04/25 PHP
PHP实现动态柱状图改进版
2015/03/30 PHP
Yii2如何批量添加数据
2016/05/17 PHP
php+Ajax处理xml与json格式数据的方法示例
2019/03/04 PHP
再说AutoComplete自动补全之实现原理
2011/11/05 Javascript
jQuery中实现动画效果的基本操作介绍
2013/04/16 Javascript
jquery获取iframe中的dom对象(两种方法)
2013/07/02 Javascript
JS+CSS实现带关闭按钮DIV弹出窗口的方法
2015/02/27 Javascript
JavaScript获取DOM元素的11种方法总结
2015/04/25 Javascript
使用Node.js配合Nginx实现高负载网络
2015/06/28 Javascript
全面解析DOM操作和jQuery实现选项移动操作代码分享
2016/06/07 Javascript
Angular在一个页面中使用两个ng-app的方法(二)
2017/02/20 Javascript
利用n工具轻松管理Node.js的版本
2017/04/21 Javascript
Vuejs实现购物车功能
2017/11/05 Javascript
有趣的JavaScript隐式类型转换操作实例分析
2020/05/02 Javascript
vue中父子组件传值,解决钩子函数mounted只运行一次的操作
2020/07/27 Javascript
django实现分页的方法
2015/05/26 Python
Python温度转换实例分析
2018/01/17 Python
详解Python 数据库的Connection、Cursor两大对象
2018/06/25 Python
利用ctypes获取numpy数组的指针方法
2019/02/12 Python
PyQt5实现简易计算器
2020/05/30 Python
python实现视频分帧效果
2019/05/31 Python
12个步骤教你理解Python装饰器
2019/07/01 Python
Python调用shell命令常用方法(4种)
2020/05/11 Python
python实现文件+参数发送request的实例代码
2021/01/05 Python
python实现杨辉三角的几种方法代码实例
2021/03/02 Python
机械电子工程毕业生自荐信
2013/11/23 职场文书
学习党课思想汇报
2013/12/29 职场文书
青春演讲稿范文
2014/05/08 职场文书
模具专业自荐信
2014/05/29 职场文书
个人遵守党的政治纪律情况对照检查材料思想汇报
2014/09/25 职场文书
写给同学的新学期寄语
2015/02/27 职场文书
2015年药房工作总结
2015/04/25 职场文书
民事调解书范文
2015/05/20 职场文书
Java+swing实现抖音上的表白程序详解
2022/06/25 Java/Android