{"id":1102,"date":"2016-08-31T18:08:57","date_gmt":"2016-08-31T10:08:57","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=1102"},"modified":"2016-08-31T18:08:57","modified_gmt":"2016-08-31T10:08:57","slug":"%e9%a1%af%e7%a4%ba%e5%b9%b4%e6%9b%86","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=1102","title":{"rendered":"[ PHP ] &#8211; \u986f\u793a\u5e74\u66c6"},"content":{"rendered":"<p>\t\t\t\t\u986f\u793a\u5e74\u66c6<br \/>\n\u4e4b\u524d\u6709\u767c\u4e00\u7bc7 <a href=\"https:\/\/www.webteach.tw\/?p=130\" target=\"_blank\" rel=\"noopener noreferrer\">\u986f\u793a\u6708\u66c6<\/a> \uff0c\u9019\u6b21\u5c31\u4f86\u7bc7 \u986f\u793a\u5e74\u66c6\uff1b\u65b9\u6cd5\u5927\u540c\u5c0f\u7570\u3002<br \/>\n[php]<br \/>\n&lt;?php<br \/>\n\t$year=2016;<br \/>\n\t$mtxt=array(1=&gt;&#8217;\u4e00&#8217;,2=&gt;&#8217;\u4e8c&#8217;,3=&gt;&#8217;\u4e09&#8217;,4=&gt;&#8217;\u56db&#8217;,5=&gt;&#8217;\u4e94&#8217;,6=&gt;&#8217;\u516d&#8217;,7=&gt;&#8217;\u4e03&#8217;,8=&gt;&#8217;\u516b&#8217;,9=&gt;&#8217;\u4e5d&#8217;,10=&gt;&#8217;\u5341&#8217;,11=&gt;&#8217;\u5341\u4e00&#8217;,12=&gt;&#8217;\u5341\u4e8c&#8217;,);<br \/>\n\tfor($m=1;$m&lt;=12;$m++){<br \/>\n\t\techo &#8216;&lt;div style=&quot;width:240px;float: left;&quot;&gt;&#8217;;<br \/>\n\t\t$YM = $year.&#8217;-&#8216;.$m;<br \/>\n\t\t$day=getthemonth($YM);<br \/>\n\t\techo &#8216;&lt;b&gt;&#8217;.$YM.'&lt;\/b&gt;&#8217;;<br \/>\n\t\techo &#8216;&lt;br\/&gt;&#8217;;<br \/>\n\t\techo &#8216;\u9019\u500b\u6708\u6709\u5e7e &#8216;.$dayCount = date(&quot;t&quot;,strtotime($day[0])).&#8217; \u5929&#8217;;<br \/>\n\t\techo &#8216;&lt;br\/&gt;&#8217;;<br \/>\n\t\techo &#8216;\u9019\u500b\u6708\u7684\u7b2c\u4e00\u5929\u662f\u79ae\u62dc &#8216;.$weekday  = date(&#8216;w&#8217;, strtotime($day[0]));<br \/>\n\t\techo &#8216;&lt;br\/&gt;&#8217;;<br \/>\n\t\techo &#8216;\u9019\u500b\u6708\u7684\u6700\u5f8c\u4e00\u5929\u662f\u79ae\u62dc &#8216;.date(&#8216;w&#8217;, strtotime($day[1]));<br \/>\n\t\techo &#8216;&lt;br\/&gt;&#8217;;<br \/>\n\t\techo $d_first=date(&quot;j&quot;,strtotime($day[0])).&#8217; &#8211; &#8216;.$d_last=date(&quot;j&quot;,strtotime($day[1]));<br \/>\n\t\t$d_last=$dayCount+$weekday-1;\/\/\u82e5\u7b2c\u4e00\u5929\u4e0d\u662f\u79ae\u62dc\u65e5<br \/>\n\t\techo &#8216;&lt;br\/&gt;&#8217;;<br \/>\n\t\techo &#8216;last:&#8217;.$d_last;<br \/>\n\t\t$sday=1;<br \/>\n\t\techo $mtxt[$m].&#8217;\u6708&#8217;;<br \/>\n\t\techo &#8216;&lt;table&gt;&lt;tr&gt;&lt;td&gt;\u65e5&lt;\/td&gt;&lt;td&gt;\u4e00&lt;\/td&gt;&lt;td&gt;\u4e8c&lt;\/td&gt;&lt;td&gt;\u4e09&lt;\/td&gt;&lt;td&gt;\u56db&lt;\/td&gt;&lt;td&gt;\u4e94&lt;\/td&gt;&lt;td&gt;\u516d&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&#8217;;<br \/>\n\t\tfor($i=1;$i&lt;=42;$i++){<br \/>\n\t\t\techo &#8216;&lt;td style=&quot;background-color:&#8217;.($i&gt;$weekday &amp;&amp; $i&lt;=$d_last?&#8217;#f0f0f0&#8242;:&#8217;#ffffff&#8217;)<br \/>\n                 .&#8217;;width:40px;height:40px;border:#ffffff 1px solid;&quot;&gt;&#8217;.($i&gt;$weekday &amp;&amp; $i&lt;=$d_last ?'[&#8216;.$sday.&#8217;]&#8217;:&#8221;).'&lt;\/td&gt;&#8217;.($i%7==0?'&lt;\/tr&gt;&#8217;:&#8221;);<br \/>\n\t\t\t$sday=($i+1&gt;$weekday?$sday+1:1);<br \/>\n\t\t}<br \/>\n\t\techo &#8216;&lt;\/table&gt;&lt;\/div&gt;&#8217;;<br \/>\n\t}<br \/>\n\tfunction getthemonth($date)<br \/>\n    {<br \/>\n        $firstday = date(&#8216;Y-m-01&#8217;, strtotime($date));\/\/\u53d6\u5f97\u8a72\u65e5\u671f\u6708\u4efd\u7684\u7b2c\u4e00\u5929<br \/>\n        $lastday = date(&#8216;Y-m-d&#8217;, strtotime(&quot;$firstday +1 month -1 day&quot;));\/\/\u53d6\u5f97\u8a72\u65e5\u671f\u6708\u4efd\u7684\u6700\u5f8c\u4e00\u5929<br \/>\n        return array($firstday,$lastday);<br \/>\n    }<br \/>\n?&gt;<br \/>\n[\/php]\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u986f\u793a\u5e74\u66c6 \u4e4b\u524d\u6709\u767c\u4e00\u7bc7 \u986f\u793a\u6708\u66c6 \uff0c\u9019\u6b21\u5c31\u4f86\u7bc7 \u986f&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2201,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45],"tags":[448,834],"class_list":["post-1102","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-date","tag-php","tag-834","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/1102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1102"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/1102\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/2201"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}