php日历[测试通过]


Posted in PHP onMarch 27, 2008

比较不错的一款php日历代码

<?php 
/** 
* 日历 
* 
* Copyright(c) 2007 by 陈毅鑫(深空). All rights reserved 
* To contact the author write to {@link mailto:shenkong@php.net} 
* @author 陈毅鑫(深空) 
*/ 
if (function_exists('date_default_timezone_set')) { 
date_default_timezone_set('Asia/Chongqing'); 
} 
$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); 
$date = getdate(strtotime($date)); 
$end = getdate(mktime(0, 0, 0, $date['mon'] + 1, 1, $date['year']) - 1); 
$start = getdate(mktime(0, 0, 0, $date['mon'], 1, $date['year'])); 
$pre = date('Y-m-d', $start[0] - 1); 
$next = date('Y-m-d', $end[0] + 86400); 
$html = '<table border="1">'; 
$html .= '<tr>'; 
$html .= '<td><a href="' . $PHP_SELF . '?date=' . $pre . '">-</a></td>'; 
$html .= '<td colspan="5">' . $date['year'] . ';' . $date['month'] . '</td>'; 
$html .= '<td><a href="' . $PHP_SELF . '?date=' . $next . '">+</a></td>'; 
$html .= '</tr>'; 
$arr_tpl = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => ''); 
$date_arr = array(); 
$j = 0; 
for ($i = 0; $i < $end['mday']; $i++) { 
if (!isset($date_arr[$j])) { 
$date_arr[$j] = $arr_tpl; 
} 
$date_arr[$j][($i+$start['wday'])%7] = $i+1; 
if ($date_arr[$j][6]) { 
$j++; 
} 
} 
foreach ($date_arr as $value) { 
$html .= '<tr>'; 
foreach ($value as $v) { 
if ($v) { 
if ($v == $date['mday']) { 
$html .= '<td><b>' . $v . '</b></td>'; 
} else { 
$html .= '<td>' . $v . '</td>'; 
} 
} else { 
$html .= '<td> </td>'; 
} 
} 
$html .= '</tr>'; 
} 
$html .= '</table>'; 
echo $html; 
?>

php日历代码2
<?php 
/** 
* 日历 
*/ 
if (function_exists('date_default_timezone_set')) { 
date_default_timezone_set('Asia/Chongqing'); 
} 
$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); 
$date = getdate(strtotime($date)); 
$end = getdate(mktime(0, 0, 0, $date['mon'] + 1, 1, $date['year']) - 1); 
$start = getdate(mktime(0, 0, 0, $date['mon'], 1, $date['year'])); 
$pre = date('Y-m-d', $start[0] - 1); 
$next = date('Y-m-d', $end[0] + 86400); 
$html = '<table width="200" border="1" cellspacing="0" bordercolor="#999999" 
align="center" style="line-height:150%; font-family:Verdana,宋体; font-size: 12px;">'; 
$html .= '<tr>'; 
$html .= '<td><a href="' . $PHP_SELF . '?date=' . $pre . '">-</a></td>'; 
$html .= '<td colspan="5">' . $date['year'] . ';' . $date['month'] . '</td>'; 
$html .= '<td><a href="' . $PHP_SELF . '?date=' . $next . '">+</a></td>'; 
$html .= '</tr>'; 
$arr_tpl = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => ''); 
$date_arr = array(); 
$j = 0; 
for ($i = 0; $i < $end['mday']; $i++) { 
if (!isset($date_arr[$j])) { 
$date_arr[$j] = $arr_tpl; 
} 
$date_arr[$j][($i+$start['wday'])%7] = $i+1; 
if ($date_arr[$j][6]) { 
$j++; 
} 
} 
foreach ($date_arr as $value) { 
$html .= '<tr>'; 
foreach ($value as $v) { 
if ($v) { 
if ($v == $date['mday']) { 
$html .= '<td><b>' . $v . '</b></td>'; 
} else { 
$html .= '<td>' . $v . '</td>'; 
} 
} else { 
$html .= '<td> </td>'; 
} 
} 
$html .= '</tr>'; 
} 
$html .= '</table>'; 
echo $html; 
?>

下面这个也不错,提示有错误,思路清晰
<?php 
function calendar() 
{ 
    if($_GET['ym']) 
    { 
        $year = substr($_GET['ym'],0,4); 
        $month = substr($_GET['ym'],4,(strlen($_GET['ym'])-4));         if($month>12) 
        { 
            $year += floor($month/12); 
            $month = $month % 12; 
        } 
        if($year > 2030) $year = 2030; 
        if($year < 1980) $year = 1980; 
    } 
    $year = isset($year) ? $year : date('Y'); 
    $month = isset($month) ? $month : date('n'); 
    if($year==date('Y') && $month==date('n')) $today = date('j'); 
    if($month-1 == 0) 
        $prevmonth = ($year - 1)."12"; 
    else $prevmonth = $year.($month - 1); 
    if($month+1 == 13) 
        $nextmonth = ($year+1)."1"; 
    else $nextmonth = $year.($month+1); 
    $prevyear = ($year - 1).$month; 
    $nextyear = ($year + 1).$month; 
    echo <<<VKN 
        <table width="200" border="0" cellpadding="2" cellspacing="2"> 
  <tr> 
    <td class="weekday"><a href="?ym=$prevyear"><<</a></td> 
    <td class="normalday"><a href="?ym=$prevmonth"><</a></td> 
    <td colspan="3" class="normalday">$year - $month</td> 
    <td class="normalday"><a href="?ym=$nextmonth">></a></td> 
    <td class="weekday"><a href="?ym=$nextyear">>></a></td> 
  </tr> 
  <tr> 
    <td width="27" class="weekday">日</td> 
    <td width="27" class="normalday">一</td> 
    <td width="27" class="normalday">二</td> 
    <td width="27" class="normalday">三</td> 
    <td width="27" class="normalday">四</td> 
    <td width="27" class="normalday">五</td> 
    <td width="27" class="weekday">六</td> 
  </tr> 
VKN; 
    $nowtime = mktime(0,0,0,$month,1,$year);//当月1号转为秒 
    $daysofmonth = date(t,$nowtime);//当月天数 
    $weekofbeginday = date(w,$nowtime);//当月第一天是星期几 
    $weekofendday = date(w,mktime(0,0,0,$month+1,0,$year));//当月最后一天是星期几 
    $daysofprevmonth = date(t,mktime(0,0,0,$month,0,$year));//上个月天数 
    $count = 1;//计数 
    //列出上月后几天 
    for($i = 1 ; $i <= $weekofbeginday ; $i++) 
        { 
            echo     "<td class='othermonth'>".($daysofprevmonth-$weekofbeginday+$i)."</td>"; 
            $count++; 
        } 
    //当月全部 
    for($i = 1 ; $i <= $daysofmonth ; $i++) 
        { 
            $css = ($count%7==0 || $count%7==1)?"weekday":"normalday"; 
            if($i == $today) $css .= "today"; 
            echo     "<td class='".$css."'>".$i."</td>"; 
            if($count%7==0) echo "</tr><tr>"; 
            $count++; 
        } 
    //下月前几天 
    for ($i = 1;$i <= 6-$weekofendday;$i++) 
        { 
            echo     "<td class='othermonth'>".$i."</td>"; 
        } 
    echo <<<VKN 
          <tr> 
    <td colspan="7"></td> 
  </tr> 
</table> 
VKN; 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>calendar</title> 
<style type="text/css"> 
<!-- 
.weekday { 
    font-size: 9pt; 
    color: #FF0000; 
    text-align: center; 
} 
.normalday { 
    font-size: 9pt; 
    color: #000000; 
    text-align: center; 
} 
.weekdaytoday { 
    font-size: 9pt; 
    color: #FF0000; 
    text-align: center; 
    background-color: #FFD9D9; 
    font-weight: bold; 
} 
.normaldaytoday { 
    font-size: 9pt; 
    color: #000000; 
    text-align: center; 
    background-color: #DDDDDD; 
    font-weight: bold; 
} 
.othermonth { 
    font-size: 9pt; 
    font-style: italic; 
    color: #999999; 
    text-align: center; 
} 
--> 
</style> 
</head> 
<body> 
<?php calendar();?> 
</body> 
</html>
PHP 相关文章推荐
用PHP中的 == 运算符进行字符串比较
Nov 26 PHP
fleaphp crud操作之findByField函数的使用方法
Apr 23 PHP
php字符串分割函数explode的实例代码
Feb 07 PHP
PHP 异步执行方法,模拟多线程的应用分析
Jun 03 PHP
php解析html类库simple_html_dom(详细介绍)
Jul 05 PHP
php将mysql数据库整库导出生成sql文件的具体实现
Jan 08 PHP
ThinkPHP模板判断输出Present标签用法详解
Jun 30 PHP
浅析php-fpm静态和动态执行方式的比较
Nov 09 PHP
php中简单的对称加密算法实现
Jan 05 PHP
php获取当前url地址的方法小结
Jan 10 PHP
PHP实现对文件锁进行加锁、解锁操作的方法
Jul 04 PHP
PHP在同一域名下两个不同的项目做独立登录机制详解
Sep 22 PHP
PHP与MySQL开发中页面乱码的产生与解决
Mar 27 #PHP
php中cookie的作用域
Mar 27 #PHP
简单的PHP图片上传程序
Mar 27 #PHP
php中变量及部分适用方法
Mar 27 #PHP
php Undefined index和Undefined variable的解决方法
Mar 27 #PHP
php.ini中的php-5.2.0配置指令详解
Mar 27 #PHP
一家之言的经验之谈php+mysql扎实个人基本功
Mar 27 #PHP
You might like
php关于array_multisort多维数组排序的使用说明
2011/01/04 PHP
php图片上传存储源码并且可以预览
2011/08/26 PHP
2014年10个最佳的PHP图像操作库
2014/07/14 PHP
PHP Header用于页面跳转时的几个注意事项
2016/10/21 PHP
Tips 带三角可关闭的文字提示
2010/10/06 Javascript
js新闻滚动 js如何实现新闻滚动效果
2013/01/07 Javascript
JavaScript动态操作表格实例(添加,删除行,列及单元格)
2013/11/25 Javascript
js中使用replace方法完成某个字符的转换
2014/08/20 Javascript
js数值计算时使用parseInt进行数据类型转换(jquery)
2014/10/07 Javascript
全面了解JavaScript的数据类型转换
2016/07/01 Javascript
Bootstrap源码学习笔记之bootstrap进度条
2016/12/24 Javascript
提高Node.js性能的应用技巧分享
2017/08/10 Javascript
基于cropper.js封装vue实现在线图片裁剪组件功能
2018/03/01 Javascript
vue组件中使用props传递数据的实例详解
2018/04/08 Javascript
详细讲解如何创建, 发布自己的 Vue UI 组件库
2019/05/29 Javascript
js JSON.stringify()基础详解
2019/06/19 Javascript
[02:12]探秘2016国际邀请赛中国区预选赛选手房间
2016/06/25 DOTA
python 控制语句
2011/11/03 Python
python基于xml parse实现解析cdatasection数据
2014/09/30 Python
Django之form组件自动校验数据实现
2020/01/14 Python
python判断字符串以什么结尾的实例方法
2020/09/18 Python
实习求职信
2013/12/01 职场文书
婚庆公司的创业计划书
2014/01/22 职场文书
安全检查管理制度
2014/02/02 职场文书
售后服务经理岗位职责范本
2014/02/22 职场文书
租赁协议书范本
2014/04/22 职场文书
学雷锋演讲稿汇总
2014/05/10 职场文书
应届毕业生自荐书
2014/06/18 职场文书
老兵退伍标语
2014/10/07 职场文书
党的群众路线教育实践活动查摆问题及整改措施
2014/10/10 职场文书
无子女夫妻离婚协议书(4篇)
2014/10/20 职场文书
前台接待岗位职责范本
2015/04/03 职场文书
刑事附带民事诉讼答辩状
2015/05/22 职场文书
申请吧主发表的感言
2015/08/03 职场文书
旷工检讨书大全
2015/08/15 职场文书
教你用python控制安卓手机
2021/05/13 Python