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获取汉字的拼音(全部与首字母)
Jun 27 PHP
PHP实现格式化文件数据大小显示的方法
Jan 03 PHP
php实现微信公众号主动推送消息
Dec 31 PHP
Zend Framework教程之Application和Bootstrap用法详解
Mar 10 PHP
Yii中的cookie的发送和读取
Jul 27 PHP
PHP设置images目录不充许http访问的方法
Nov 01 PHP
php+ajax实现仿百度查询下拉内容功能示例
Oct 20 PHP
Thinkphp 5.0实现微信企业付款到零钱
Sep 30 PHP
PHP开发实现快递查询功能详解
Apr 08 PHP
tp5(thinkPHP5框架)captcha验证码配置及验证操作示例
May 28 PHP
Thinkphp 3.2框架使用Redis的方法详解
Oct 24 PHP
php7 参数、整形及字符串处理机制修改实例分析
May 25 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 header()函数使用说明
2008/07/10 PHP
php数组函数序列之krsort()- 对数组的元素键名进行降序排序,保持索引关系
2011/11/02 PHP
php无限极分类实现的两种解决方法
2013/04/28 PHP
Codeigniter购物车类不能添加中文的解决方法
2014/11/29 PHP
ThinkPHP3.1.x修改成功与失败跳转页面的方法
2017/09/29 PHP
详解PHP文件的自动加载(autoloading)
2018/02/04 PHP
php微信开发之关注事件
2018/06/14 PHP
php回调函数处理数组操作示例
2020/04/13 PHP
会自动逐行上升的文本框
2006/06/30 Javascript
对YUI扩展的Gird组件 Part-1
2007/03/10 Javascript
jquery 常用操作整理 基础入门篇
2009/10/14 Javascript
Confirmer JQuery确认对话框组件
2010/06/09 Javascript
设置iframe的document.designMode后仅Firefox中其body.innerHTML为br
2012/02/27 Javascript
JS设置cookie、读取cookie、删除cookie
2015/04/17 Javascript
原生js实现图片轮播特效
2015/12/18 Javascript
浅谈js的html元素的父节点,子节点
2016/08/06 Javascript
NodeJs测试框架Mocha的安装与使用
2017/03/28 NodeJs
Vue+Express实现登录状态权限验证的示例代码
2019/05/05 Javascript
vue滚动固定顶部及修改样式的实例代码
2019/05/30 Javascript
Vue 中使用富文本编译器wangEditor3的方法
2019/09/26 Javascript
django轻松使用富文本编辑器CKEditor的方法
2017/03/30 Python
Python3计算三角形的面积代码
2017/12/18 Python
python 异或加密字符串的实例
2018/10/14 Python
python 提取key 为中文的json 串方法
2018/12/31 Python
Python 3.8正式发布,来尝鲜这些新特性吧
2019/10/15 Python
通过实例解析Python调用json模块
2019/12/11 Python
使用darknet框架的imagenet数据分类预训练操作
2020/07/07 Python
类、抽象类、接口的差异
2016/06/13 面试题
传媒专业推荐信范文
2013/11/23 职场文书
快餐公司创业计划书
2014/04/29 职场文书
2014年学生会主席工作总结
2014/11/07 职场文书
八月迷情观后感
2015/06/11 职场文书
小学中队委竞选稿
2015/11/20 职场文书
关于@OnetoMany关系映射的排序问题,使用注解@OrderBy
2021/12/06 Java/Android
详解OpenCV获取高动态范围(HDR)成像
2022/04/29 Python
使用Python开发冰球小游戏
2022/04/30 Python