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 相关文章推荐
cmd下运行php脚本
Nov 25 PHP
Windows下XDebug 手工配置与使用说明
Jul 11 PHP
php 日期和时间的处理-郑阿奇(续)
Jul 04 PHP
php实现aes加密类分享
Feb 16 PHP
Fatal error: session_start(): Failed to initialize storage module: files问题解决方法
May 04 PHP
php实现上传图片保存到数据库的方法
Feb 11 PHP
纯php生成随机密码
Oct 30 PHP
PHP6新特性分析
Mar 03 PHP
PHP单例模式是什么 php实现单例模式的方法
May 14 PHP
PHP使用文件锁解决高并发问题示例
Mar 29 PHP
PHP结合Ffmpeg快速搭建流媒体服务的实践记录
Oct 31 PHP
php实现将数组或对象写入到文件的方法小结【三种方法】
Apr 22 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
全国FM电台频率大全 - 13 福建省
2020/03/11 无线电
使用PHP实现阻止用户上传成人照片或者裸照
2014/12/25 PHP
PHP实现获取FLV文件的时间
2015/02/10 PHP
php计算多个集合的笛卡尔积实例详解
2017/02/16 PHP
php 使用 __call实现重载功能示例
2019/11/18 PHP
jquery图形密码实现方法
2015/03/11 Javascript
JavaScript父子窗体间的调用方法
2015/03/31 Javascript
jQuery 弹出层插件(推荐)
2016/05/24 Javascript
javascript解决小数的加减乘除精度丢失的方案
2016/05/31 Javascript
浅谈Vue.js应用的四种AJAX请求数据模式
2017/08/30 Javascript
在vue中使用Autoprefixed的方法
2018/07/27 Javascript
vue 优化CDN加速的方法示例
2018/09/19 Javascript
JS中appendChild追加子节点无效的解决方法
2018/10/14 Javascript
详解三种方式解决vue中v-html元素中标签样式
2018/11/22 Javascript
React传值 组件传值 之间的关系详解
2019/08/26 Javascript
Quasar Input:type=&quot;number&quot; 去掉上下小箭头 实现加减按钮样式功能
2020/04/09 Javascript
Python解析网页源代码中的115网盘链接实例
2014/09/30 Python
Python格式化压缩后的JS文件的方法
2015/03/05 Python
Python json模块dumps、loads操作示例
2018/09/06 Python
python/sympy求解矩阵方程的方法
2018/11/08 Python
利用Python实现微信找房机器人实例教程
2019/03/10 Python
详解Python IO编程
2020/07/24 Python
Python Socket多线程并发原理及实现
2020/12/11 Python
html如何对span设置宽度
2019/10/30 HTML / CSS
哥伦比亚加拿大官网:Columbia Sportswear Canada
2020/09/07 全球购物
局域网定义和特性
2016/01/23 面试题
公司自我介绍演讲稿
2014/08/21 职场文书
农村党支部书记四风问题个人对照检查材料
2014/09/21 职场文书
召开会议通知范文
2015/04/15 职场文书
小学生暑假生活总结
2015/07/13 职场文书
婚庆答谢词大全
2015/09/29 职场文书
Canvas三种动态画圆实现方法说明(小结)
2021/04/16 Javascript
关于html选择框创建占位符的问题
2021/06/09 HTML / CSS
Vue实现导入Excel功能步骤详解
2021/07/03 Vue.js
sql通过日期判断年龄函数的示例代码
2021/07/16 SQL Server
Python初识逻辑与if语句及用法大全
2021/08/07 Python