{"id":130,"date":"2015-06-12T17:35:31","date_gmt":"2015-06-12T09:35:31","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=130"},"modified":"2015-06-12T17:35:31","modified_gmt":"2015-06-12T09:35:31","slug":"php-%e9%a1%af%e7%a4%ba%e6%97%a5%e6%9b%86","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=130","title":{"rendered":"[ PHP ] &#8211; \u986f\u793a\u6708\u66c6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4f7f\u7528php\u986f\u793a\u6708\u66c6\uff0c\u53ef\u5207\u63db\u6708\u4efd\u3002<\/p>\n\n\n<pre class=\"wp-block-code\"><code>\n&lt;?php\nfunction getthemonth($date){\n    $firstday = date('Y-m-01', strtotime($date));\/\/\u53d6\u5f97\u8a72\u65e5\u671f\u6708\u4efd\u7684\u7b2c\u4e00\u5929\n    $lastday = date('Y-m-d', strtotime(\"$firstday +1 month -1 day\"));\/\/\u53d6\u5f97\u8a72\u65e5\u671f\u6708\u4efd\u7684\u6700\u5f8c\u4e00\u5929\n    return array($firstday,$lastday);\n}\n$YM = (isset($_GET&#91;'date'])?$_GET&#91;'date']:date(\"Y-m\"));\n$day=getthemonth($YM);\necho '&lt;b>'.$YM.'&lt;\/b>';\necho '&lt;br\/>';\necho '\u9019\u500b\u6708\u6709\u5e7e '.$dayCount = date(\"t\",strtotime($day&#91;0])).' \u5929';\necho '&lt;br\/>';\necho '\u9019\u500b\u6708\u7684\u7b2c\u4e00\u5929\u662f\u79ae\u62dc '.$weekday = date('w', strtotime($day&#91;0]));\necho '&lt;br\/>';\necho '\u9019\u500b\u6708\u7684\u6700\u5f8c\u4e00\u5929\u662f\u79ae\u62dc '.date('w', strtotime($day&#91;1]));\necho '&lt;br\/>';\necho $d_first=date(\"j\",strtotime($day&#91;0])).' - '.$d_last=date(\"j\",strtotime($day&#91;1]));\n$d_last=$dayCount+$weekday-1;\/\/\u82e5\u7b2c\u4e00\u5929\u4e0d\u662f\u79ae\u62dc\u65e5\necho '&lt;br\/>';\necho 'last:'.$d_last;\n?>\n&lt;div style=\"width:1024;background-color:#333;\">\n&lt;?php\n$i=1;\nfor($x=0;$x&lt;=41;$x++){\/\/\u986f\u793a42\u683c\n    echo '&lt;div style=\"background-color:'.($x+1>$weekday &amp;&amp; $x&lt;=$d_last?'#f0f0f0':'#ffffff')\/\/\n.';width:140px;height:140px;float:left; border:#ffffff 1px solid;\">'\n.($x+1>$weekday &amp;&amp; $x&lt;=$d_last ?'&#91;'.$i.']':'').\"&lt;\/div>\";\n$i=($x+1>$weekday?$i+1:1);\n}\n?>\n&lt;\/div>\n&lt;div style=\"clear:both;width:1024;\">\n&lt;a href=\"?date=&lt;?php echo date(\"Y-m\",strtotime('-1 month',strtotime($YM)));?>\" style=\"float:left;\">\u4e0a\u500b\u6708&lt;\/a>\n&lt;a href=\"?date=&lt;?php echo date(\"Y-m\",strtotime('+1 month',strtotime($YM)));?>\" style=\"float:right;\">\u4e0b\u500b\u6708&lt;\/a>\n&lt;\/div><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528php\u986f\u793a\u6708\u66c6\uff0c\u53ef\u5207\u63db\u6708\u4efd\u3002<\/p>\n","protected":false},"author":1,"featured_media":133,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45,36],"tags":[946],"class_list":["post-130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-date","category-php","tag-946","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/130","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=130"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/133"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}