PHP日历程序编写(简单实现)
2016-03-26 17:50
751 查看
<meta charset="utf-8">
<?php
$year = isset($_GET['year']) ? $_GET['year'] : date("Y"); //当前的年
$month = isset($_GET['month']) ? $_GET['month'] : date("m"); //当前的月
$day = isset($_GET['day']) ? $_GET['day'] : date("d"); //当前的日
//当年当月的天数
//0,0,0表示小时分秒
$days = date("t", mktime(0,0,0, $month, 1, $year));
//获取当月的第一天是星期几
$startweek = date("w", mktime(0,0,0, $month, 1, $year));
echo "今天是{$year}年{$month}月{$day}日,是情人节, 还是元宵节!<br>";
echo '<table border="0" width="300" align="center">';
echo '<tr>';
echo '<th style="background:blue">日</th>';
echo '<th style="background:blue">一</th>';
echo '<th style="background:blue">二</th>';
echo '<th style="background:blue">三</th>';
echo '<th style="background:blue">四</th>';
echo '<th style="background:blue">五</th>';
echo '<th style="background:blue">六</th>';
echo '</tr>';
echo '<tr>';
for($i=0; $i<$startweek; $i++) {
echo "<td> </td>";
}
for($j=1; $j <= $days; $j++) {
$i++;
if($j==$day) {
echo "<td style='background:green'>{$j}</td>";
}else{
echo "<td>{$j}</td>";
}
if($i%7 ==0 ){
echo '</tr><tr>';
}
}
while($i%7!==0) {
echo '<td> </td>';
$i++;
}
echo '</tr>';
echo '</table>';
<?php
$year = isset($_GET['year']) ? $_GET['year'] : date("Y"); //当前的年
$month = isset($_GET['month']) ? $_GET['month'] : date("m"); //当前的月
$day = isset($_GET['day']) ? $_GET['day'] : date("d"); //当前的日
//当年当月的天数
//0,0,0表示小时分秒
$days = date("t", mktime(0,0,0, $month, 1, $year));
//获取当月的第一天是星期几
$startweek = date("w", mktime(0,0,0, $month, 1, $year));
echo "今天是{$year}年{$month}月{$day}日,是情人节, 还是元宵节!<br>";
echo '<table border="0" width="300" align="center">';
echo '<tr>';
echo '<th style="background:blue">日</th>';
echo '<th style="background:blue">一</th>';
echo '<th style="background:blue">二</th>';
echo '<th style="background:blue">三</th>';
echo '<th style="background:blue">四</th>';
echo '<th style="background:blue">五</th>';
echo '<th style="background:blue">六</th>';
echo '</tr>';
echo '<tr>';
for($i=0; $i<$startweek; $i++) {
echo "<td> </td>";
}
for($j=1; $j <= $days; $j++) {
$i++;
if($j==$day) {
echo "<td style='background:green'>{$j}</td>";
}else{
echo "<td>{$j}</td>";
}
if($i%7 ==0 ){
echo '</tr><tr>';
}
}
while($i%7!==0) {
echo '<td> </td>';
$i++;
}
echo '</tr>';
echo '</table>';
相关文章推荐
- composer安装yii2问题总结
- PHP应用日期与时间
- Laravel框架中server.php文件的作用
- PHP编译安装时候的报错
- PHP 请求转发(CURL)
- PHP设计模式 工厂设计模式
- Yii 2.0学习日记:用户登陆详细解析(上)
- ubuntu源码编译安装php
- php如何创建验证码
- PHP设计模式
- commons.net FTP 实现断点续传
- PHP系统时区设置
- zend studio svn安装过程
- PHPstorm的快捷方式
- php编程中echo用逗号和用点号连接的区别
- PHP编程效率的20个要点
- InputStream重用技巧(利用ByteArrayOutputStream)
- PHP旧的SQL接口警告信息影响XML 2016.03.25回顾
- thinkphp框架中引入ping++支付server SDK
- PHP文件的路径及操作