php Calender(日历)代码分享
2015-01-24信息快讯网
这篇文章主要介绍了php Calender(日历)代码,有需要的朋友可以参考一下
代码如下:
<?php
/**
*
* 我的日历
* date_default_timezone_set date mktime
* @param int $year
* @param int $month
* @param string $timezone
* @author fc_lamp
*/
function myCalender($year = '', $month = '', $timezone = 'Asia/Shanghai')
{
date_default_timezone_set ( $timezone );
$year = abs ( intval ( $year ) );
$month = abs ( intval ( $month ) );
//是否是32位机
if (is32())
{
if ($year < 1970 or $year >= 2038)
{
$year = date ( 'Y' );
}
} else
{
if ($year <= 0)
{
$year = date ( 'Y' );
}
}
if ($month <= 0 or $month > 12)
{
$month = date ( 'm' );
}
//上一年
$pretYear = $year - 1;
//上一月
$mpYear = $year;
$preMonth = $month - 1;
if ($preMonth <= 0)
{
$preMonth = 1;
$mpYear = $pretYear;
}
//下一年
$nextYear = $year + 1;
//下一月
$mnYear = $year;
$nextMonth = $month + 1;
if ($nextMonth > 12)
{
$nextMonth = 1;
$mnYear = $nextYear;
}
//日历头
$html = <<<HTML
<table width="500" border="1">
<tr align="center">
<td><a href="?y=$pretYear">上一年</a></td>
<td><a href="?y=$mpYear&m=$preMonth">上一月</a></td>
<td><a href="?">回到今天</a></td>
<td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td>
<td><a href="?y=$nextYear">下一年</a></td>
</tr>
<tr align="center">
<td colspan="5">{$year}年{$month}月</td>
</tr>
<tr>
<td colspan="5">
<table width="100%" border="1">
<tr align="center">
<td style="background-color:#DAF0DD;">星期一</td>
<td style="background-color:#DAF0DD;">星期二</td>
<td style="background-color:#DAF0DD;">星期三</td>
<td style="background-color:#DAF0DD;">星期四</td>
<td style="background-color:#DAF0DD;">星期五</td>
<td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td>
<td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td>
</tr>
HTML;
$currentDay = date ( 'Y-m-j' );
//当月最后一天
$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );
//循环输出天数
$day = 1;
$line = '';
while ( $day <= $lastday )
{
$cday = $year . '-' . $month . '-' . $day;
//当前星期几
$nowWeek = date ( 'N', mktime ( 0, 0, 0, $month, $day, $year ) );
if ($day == 1)
{
$line = '<tr align="center">';
$line .= str_repeat ( '<td> </td>', $nowWeek - 1 );
}
if ($cday == $currentDay)
{
$style = 'style="color:red;"';
} else
{
$style = '';
}
$line .= "<td $style>$day</td>";
//一周结束
if ($nowWeek == 7)
{
$line .= '</tr>';
$html .= $line;
$line = '<tr align="center">';
}
//全月结束
if ($day == $lastday)
{
if ($nowWeek != 7)
{
$line .= str_repeat ( '<td> </td>', 7 - $nowWeek );
}
$line .= '</tr>';
$html .= $line;
break;
}
$day ++;
}
$html .= <<<HTML
</table>
</td>
</tr>
</table>
HTML;
return $html;
}
/**
*
* 检测是否是32位机
* @author fc_lamp
* @blog: fc-lamp.blog.163.com
*/
function is32()
{
$is32 = False;
if (strtotime ( '2039-10-10' ) === False)
{
$is32 = True;
}
return $is32;
}
Zend Framework页面缓存实例
非常好用的Zend Framework分页类
PHP使用DOMDocument类生成HTML实例(包含常见标签元素)
PHP获取windows登录用户名的方法
PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
浅析application/x-www-form-urlencoded和multipart/form-data的区别
destoon安装出现Internal Server Error的解决方法
windows下配置apache+php+mysql时出现问题的处理方法
PHP中strlen()和mb_strlen()的区别浅析
ThinkPHP CURD方法之table方法详解
ThinkPHP Mobile使用方法简明教程
PHPAnalysis中文分词类详解
PHP使用Alexa API获取网站的Alexa排名例子
PHP捕获Fatal error错误的方法
ECMall支持SSL连接邮件服务器的配置方法详解
浅析ThinkPHP中的pathinfo模式和URL重写
深入解读php中关于抽象(abstract)类和抽象方法的问题分析
zend framework文件上传功能实例代码
php calender(日历)二个版本代码示例(解决2038问题)
解决file_get_contents无法请求https连接的方法
PHP eval函数使用介绍
Server.HTMLEncode让代码在页面里显示为源代码
PHP上传文件时文件过大$_FILES为空的解决方法
php解析xml提示Invalid byte 1 of 1-byte UTF-8 sequence错误的处理方法
PHP PDOStatement:bindParam插入数据错误问题分析
PHP反射类ReflectionClass和ReflectionObject的使用方法
PHP set_error_handler()函数使用详解(示例)
PHP开发工具ZendStudio下Xdebug工具使用说明详解
php mysql_real_escape_string函数用法与实例教程
分享下PHP register_globals 值为on与off的理解