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实现采集程序原理和简单示例代码
Mar 18 PHP
php 调用远程url的六种方法小结
Nov 02 PHP
在PHP中使用redis
Nov 04 PHP
php采用curl模仿登录人人网发布动态的方法
Nov 07 PHP
Yii分页用法实例详解
Dec 04 PHP
php递归遍历多维数组的方法
Apr 18 PHP
PHP获取指定时间段之间的 年,月,天,时,分,秒
Jun 05 PHP
php简单生成一组与多组随机字符串的方法
May 09 PHP
PHP基于堆栈实现的高级计算器功能示例
Sep 15 PHP
PHP生成腾讯云COS接口需要的请求签名
May 20 PHP
php面试中关于面向对象的相关问题
Feb 13 PHP
Yii实现微信公众号场景二维码的方法实例
Aug 30 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
综合图片计数器
2006/10/09 PHP
php随机输出名人名言的代码
2012/10/07 PHP
PHP中的魔术方法总结和使用实例
2015/05/11 PHP
PHP使用token防止表单重复提交的方法
2016/04/07 PHP
thinkPHP+PHPExcel实现读取文件日期的方法(含时分秒)
2016/07/07 PHP
PHP实现活动人选抽奖功能
2017/04/19 PHP
YII框架实现自定义第三方扩展操作示例
2019/04/26 PHP
表格 隔行换色升级版
2009/11/07 Javascript
JavaScript创建类/对象的几种方式概述及实例
2013/05/06 Javascript
js简单实现交换Li的值
2014/05/22 Javascript
javascript 10进制和62进制的相互转换
2014/07/31 Javascript
node.js中的fs.readFile方法使用说明
2014/12/15 Javascript
JavaScript数据结构与算法之栈详解
2015/03/12 Javascript
js命名空间写法示例
2015/12/18 Javascript
JavaScript html5利用FileReader实现上传功能
2020/03/27 Javascript
对VUE中的对象添加属性
2018/09/18 Javascript
jquery获取file表单选择文件的路径、名字、大小、类型
2019/01/18 jQuery
JS实现移动端双指缩放和旋转方法
2019/12/13 Javascript
使用npm命令提示: 'npm' 不是内部或外部命令,也不是可运行的程序的处理方法
2020/05/14 Javascript
快速了解Vue父子组件传值以及父调子方法、子调父方法
2020/07/15 Javascript
解决vue+elementui项目打包后样式变化问题
2020/08/03 Javascript
[01:42]DOTA2 – 虚无之灵
2019/08/25 DOTA
Python实现登录接口的示例代码
2017/07/21 Python
python绘制简单折线图代码示例
2017/12/19 Python
Python安装OpenCV的示例代码
2020/03/05 Python
python 两种方法修改文件的创建时间、修改时间、访问时间
2020/09/26 Python
详解matplotlib绘图样式(style)初探
2021/02/03 Python
AmazeUI 输入框组的示例代码
2020/08/14 HTML / CSS
Bench加拿大官方网站:英国城市服装品牌
2017/11/03 全球购物
List, Set, Map是否继承自Collection接口?
2016/05/16 面试题
活动总结怎么写
2014/04/28 职场文书
党员干部形式主义个人整改措施
2014/09/17 职场文书
2015年护士医德医风自我评价
2015/03/03 职场文书
Shell脚本一键安装Nginx服务自定义Nginx版本
2022/03/20 Servers
openGauss数据库JDBC环境连接配置的详细过程(Eclipse)
2022/06/01 Java/Android