php基础练习--简易万年历

王朝学院·作者佚名  2016-05-25
窄屏简体版  字體: 小  |  中  |  大  |  超大  

php基础练习--简易万年历php简易万年历:

<?php /** * calendar */ header("content-type:text/html;charset=utf-8"); @$year = $_GET['y'] ? $_GET['y'] : date("Y"); @$month = $_GET['m'] ? $_GET['m'] : date("m"); $days = date("t", strtotime("{$year}-{$month}-1")); $weeks = date("w", strtotime("{$year}-{$month}-1")); echo "<center>"; echo "<h2>{$year}-{$month}</h2>"; echo "<table width='700px' border='1px' cellpadding='3' cellspacing='0'>"; echo "<tr>"; echo "<th>星期日</th>"; echo "<th>星期一</th>"; echo "<th>星期二</th>"; echo "<th>星期三</th>"; echo "<th>星期四</th>"; echo "<th>星期五</th>"; echo "<th>星期六</th>"; echo "</tr>"; for ($i = 1 - $weeks; $i <= $days;) { echo "<tr>"; for ($j=0; $j <7 ; $j++) { if ($i > $days || $i <= 0) { echo "<td>&nbsp;</td>"; } else { echo "<td>{$i}</td>"; } $i++; } echo "</tr>"; } echo "</table>"; if ($month == 1) { $PRevmonth = 12; $prevyear = $year - 1; } else { $prevmonth = $month - 1; $prevyear = $year; } if ($month == 12) { $nextmonth = 1; $nextyear =$year +1; } else { $nextmonth = $month +1; $nextyear = $year; } echo "<h3><a href='index.php?y={$prevyear}&m={$prevmonth}'>上一月</a>| <a href='index.php?y={$nextyear}&m={$nextmonth}'>下一月</a></h3>"; echo "</center>";

calendar 通过这个基础练习,主要是为了掌握for循环的运用,判断tr和td标签的位置来掌握for循环嵌套的使用。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航