PHP制作简单的日历
2014-05-28 21:21
447 查看
在这里分享一个PHP制作的日历
<?php
//万年历
if($_GET['year']){
$year = $_GET['year'];
}else{
$year = date("Y");
} //年
if($_GET['month']){
$month = $_GET['month'];
}else{
$month = date("m");
} //月
//计算该月有多少钱
$day = date("t",mktime(0,0,0,$month,1,$year));
//计算1号是周几
$w = date("w",mktime(0,0,0,$month,1,$year));
?>
<html>
<head>
<title>clander</title>
</head>
<body>
<center>
<h1><?php echo $year.'年'.$month.'月';?></h1>
<table width="600px" border="1px">
<tr>
<th style='color:#ff0000'>星期日</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th style='color:#008'>星期六</th>
</tr>
<?php
$dd = 1;
while($dd<=$day){
echo '<tr>';
for($i=0;$i<7;$i++){
if($dd<=$day && ($w<=$i ||$dd!=1)){
echo "<td>{$dd}</td>";
$dd++;
}else{
echo '<td> </td>';
}
}
echo '</tr>';
}
//处理年份越界的问题
$prey = $nexty = $year;
$prem = $nextm = $month;
if($prem<=1){
$prem = 12;
$prey--;
}else{
$prem--;
}
if($nextm>=12){
$nextm = 1;
$nexty++;
}else{
$nextm++;
}
?>
<a href="clander.php?year=<?php echo $prey ?>&month=<?php echo $prem ?>">上一月</a>
<a href="clander.php?year=<?php echo $nexty ?>&month=<?php echo $nextm?>">下一月</a>
</table>
</center>
</body>
</html>
参考图:
<?php
//万年历
if($_GET['year']){
$year = $_GET['year'];
}else{
$year = date("Y");
} //年
if($_GET['month']){
$month = $_GET['month'];
}else{
$month = date("m");
} //月
//计算该月有多少钱
$day = date("t",mktime(0,0,0,$month,1,$year));
//计算1号是周几
$w = date("w",mktime(0,0,0,$month,1,$year));
?>
<html>
<head>
<title>clander</title>
</head>
<body>
<center>
<h1><?php echo $year.'年'.$month.'月';?></h1>
<table width="600px" border="1px">
<tr>
<th style='color:#ff0000'>星期日</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th style='color:#008'>星期六</th>
</tr>
<?php
$dd = 1;
while($dd<=$day){
echo '<tr>';
for($i=0;$i<7;$i++){
if($dd<=$day && ($w<=$i ||$dd!=1)){
echo "<td>{$dd}</td>";
$dd++;
}else{
echo '<td> </td>';
}
}
echo '</tr>';
}
//处理年份越界的问题
$prey = $nexty = $year;
$prem = $nextm = $month;
if($prem<=1){
$prem = 12;
$prey--;
}else{
$prem--;
}
if($nextm>=12){
$nextm = 1;
$nexty++;
}else{
$nextm++;
}
?>
<a href="clander.php?year=<?php echo $prey ?>&month=<?php echo $prem ?>">上一月</a>
<a href="clander.php?year=<?php echo $nexty ?>&month=<?php echo $nextm?>">下一月</a>
</table>
</center>
</body>
</html>
参考图:
相关文章推荐
- 教大家制作简单的php日历
- PHP实现的简单日历代码
- PHP简单演示如何使用模板制作静态页面
- 邪恶的Php一句话木马 assert函数制作简单木马
- java简单日历的制作代码
- 用php制作简单分页(从数据库读取记录)的方法详解
- PHP+SQLITE制作简单的视频点播程序
- js制作日历1----------简单的日历
- JS制作简单的日历控件【JS Date对象操作实例演示】
- ZendStudio php WebService制作一:简单WebService Demo
- php制作日历
- Flash+PHP+Mysql简单留言本制作
- PHP + SQL + FLEX 制作简单留言板
- 文盲的 JavaScript 实战篇之二:制作一个简单的日历控件
- PHP+SQlite 制作简单的留言板
- 利用PHP制作简单的内容采集器的代码
- 用PHP+MySQL制作的一个简单的留言板
- 简单的PHP日历算法
- 使用PHP和AJAX制作日历