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 相关文章推荐
php+oracle 分页类
Oct 09 PHP
截获网站title标签之家内容的例子
Oct 09 PHP
PHP输出数组中重名的元素的几种处理方法
Sep 05 PHP
php class中self,parent,this的区别以及实例介绍
Apr 24 PHP
php 去除html标记--strip_tags与htmlspecialchars的区别详解
Jun 26 PHP
php四种基础算法代码实例
Oct 29 PHP
PHP错误Cannot use object of type stdClass as array in错误的解决办法
Jun 12 PHP
php获取Google机器人访问足迹的方法
Apr 15 PHP
Python中使用django form表单验证的方法
Jan 16 PHP
php下载远程大文件(获取远程文件大小)的实例
Jun 17 PHP
详解cookie验证的php应用的一种SSO解决办法
Oct 20 PHP
php中文语义分析实现方法示例
Sep 28 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
怎样辨别一杯好咖啡
2021/03/03 新手入门
PHP XML操作类DOMDocument
2009/12/16 PHP
Yii框架上传图片用法总结
2016/03/28 PHP
php读取torrent种子文件内容的方法(测试可用)
2016/05/03 PHP
IE与FireFox的兼容性问题分析
2007/04/22 Javascript
JS实现网页背景颜色与select框中颜色同时变化的方法
2015/02/27 Javascript
webix+springmvc session超时跳转登录页面
2016/10/30 Javascript
jQuery实现分页功能(含ajax请求、后台数据、附完整demo)
2017/04/03 jQuery
微信小程序中form 表单提交和取值实例详解
2017/04/20 Javascript
nodeJs实现基于连接池连接mysql的方法示例
2018/02/10 NodeJs
详解vue中async-await的使用误区
2018/12/05 Javascript
详解vue中axios请求的封装
2019/04/08 Javascript
基于vue 实现表单中password输入的显示与隐藏功能
2019/07/19 Javascript
Vuex 模块化使用详解
2019/07/31 Javascript
a标签调用js的方法总结
2019/09/05 Javascript
js实现移动端吸顶效果
2020/01/08 Javascript
JS数组方法shift()、unshift()用法实例分析
2020/01/18 Javascript
对Python中的@classmethod用法详解
2018/04/21 Python
python多线程之事件Event的使用详解
2018/04/27 Python
python爬虫超时的处理的实例
2018/12/19 Python
Python从单元素字典中获取key和value的实例
2018/12/31 Python
python对csv文件追加写入列的方法
2019/08/01 Python
使用Pyinstaller转换.py文件为.exe可执行程序过程详解
2019/08/06 Python
Flask 上传自定义头像的实例详解
2020/01/09 Python
Python实现括号匹配方法详解
2020/02/10 Python
Python Selenium XPath根据文本内容查找元素的方法
2020/12/07 Python
python实现定时发送邮件
2020/12/23 Python
css 如何让背景图片拉伸填充避免重复显示
2013/07/11 HTML / CSS
高级3D打印市场:Gambody
2019/12/26 全球购物
应届生会计求职信
2013/11/11 职场文书
顶撞领导检讨书
2014/01/29 职场文书
党员组织关系介绍信
2014/02/13 职场文书
电子专业毕业生自荐信
2014/05/25 职场文书
解除施工合同协议书
2014/10/17 职场文书
电影复兴之路观后感
2015/06/02 职场文书
68句权威创业名言
2019/08/26 职场文书