简单实现日历_PHP教程

php中文网
发布: 2016-07-13 10:37:54
原创
1132人浏览过

一个简单实现的日历,我不知道这段代码实现的方法有没有问题,没有参考前辈,等你理解我的烂代码之后,再欣赏一下别人的优秀代码,会更有帮助
   

代码片段(1)

[代码] [PHP]代码

view source print? 01 02 03 <meta http-equiv="&lt;/code"&gt; <code class="string"&gt;"Content-Type" content="text/html; charset=utf8" /&gt; 04 <style&gt;</style&gt; 05 #calendardiv,#calendar{width:252px;} 06 #cal_title{height:33px;line-height:33px;text-align:center;overflow:hidden;} 07 #cal_title strong{font-weight:bold;font-size:14px; } 08 #cal_title a{font-weight:bold;font-size:14px;text-decoration:none;} 09 #calendar{border-collapse:collapse;} 10 #calendar td{ 11     text-align:center; 12     width:35px; 13     height:20px; 14     line-height:20px; 15     background-color:#efefef; 16     border-bottom:1px solid #fff; 17     border-right:1px solid #fff; 18     } 19 #calendar .even td{background-color:#e6e6e6;} 20 #calendar td .current{display:block;background-color:#f60;color:#fff;} 21 #calendar .current{background-color:#f60!important;color:#fff;} 22 #week td{color:#fff;background-color:#373737;} 23 24 25 26 <?php 27     $date = isset($_GET['d']) ? intval($_GET['d']) : ''; 28     if($date) 29     { 30         $y substr($date,0,4); 31         $m substr($date,4,2); 32         $cur mktime(0,0,0,$m,1,$y); 33     } 34     else 35     { 36         $cur mktime(); 37     } 38   39     list($year,$month,$day) = explode('-',date('Y-m-d',$cur));//年月日 40     $p date('Ym',strtotime('last months',$cur));//前一月 41     $n date('Ym',strtotime('next months',$cur));//后一月 42     <code class="variable">$t date('t',$cur); //当月多少天 43     <code class="variable">$s date('w',mktime(0,0,0,$month,1,$year)); //前补空白 44     <code class="variable">$e = 6-(date('w',mktime(0,0,0,$month,<code class="variable">$t,$year)));//后补空白 45 ?&gt; 46 <div id="&lt;/code"&gt; <code class="string"&gt;"calendardiv"&gt;
47 <div id="&lt;/code"&gt; <code class="string"&gt;"cal_title"&gt;"?d==$p?&gt;" title="上一月"&gt;«  =$year?&gt;年=$month?&gt;月  "?d==$n?&gt;"title="下一月"&gt;»
48 <table id="&lt;/code"&gt; <code class="string"&gt;"calendar"&gt; 49 <tr id="&lt;/code"> <code class="string">"week"&gt;日 一 二 三 四 五 六 50 <?php 51     echo '<tr class="even">'<code class="plain">; 52     for($i=0;$i<code class="variable">$s;$i++) 53     { 54         echo '<td> </td>'; 55     } 56     for($d=1;$d<code class="variable">$t;$d++) 57     { 58         $current=$d==$day?'class="current"':'';//当前样式 59         $r = ($d+<code class="variable">$s)%7;//换行 60   61         echo "<td>$d</td>"; 62         if($r==0) 63         { 64             echo ''; 65             echo '<tr class="even">'<code class="plain">; 66         } 67     } 68     for($i=0;$i<code class="variable">$e;$i++) 69         { 70             echo '<td> </td>'; 71         } 72 ?&gt; 73

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735155.htmlTechArticle一个简单实现的日历,我不知道这段代码实现的方法有没有问题,没有参考前辈,等你理解我的烂代码之后,再欣赏一下别人的优秀代码,...
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
收藏 点赞
上一篇:大型网站架构演变和知识体系_PHP教程 下一篇:大型网络项目整体架构方案讨论擂台_PHP教程
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
相关专题
更多>
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号