{"id":118,"date":"2009-01-04T09:56:53","date_gmt":"2009-01-04T09:56:53","guid":{"rendered":"http:\/\/tw.newtonstudio.com\/?p=118"},"modified":"2009-01-04T09:56:53","modified_gmt":"2009-01-04T09:56:53","slug":"php-%e6%97%a5%e6%9b%86","status":"publish","type":"post","link":"http:\/\/tw.newtonstudio.com\/?p=118","title":{"rendered":"PHP \u65e5\u66c6"},"content":{"rendered":"<blockquote><p>&lt;?php<\/p>\n<p>\/\/This gets today&#8217;s date<br \/>\n$date =time () ;<\/p>\n<p>\/\/This puts the day, month, and year in seperate variables<br \/>\n$day = date(&#8216;d&#8217;, $date) ;<br \/>\n$month = date(&#8216;m&#8217;, $date) ;<br \/>\n$year = date(&#8216;Y&#8217;, $date) ;<\/p>\n<p>\/\/Here we generate the first day of the month<br \/>\n$first_day = mktime(0,0,0,$month, 1, $year) ;<\/p>\n<p>\/\/This gets us the month name<br \/>\n$title = date(&#8216;F&#8217;, $first_day) ;<\/p>\n<p>\/\/Here we find out what day of the week the first day of the month falls on<br \/>\n$day_of_week = date(&#8216;D&#8217;, $first_day) ;<\/p>\n<p>\/\/Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero<br \/>\nswitch($day_of_week){<br \/>\ncase &#8220;Sun&#8221;: $blank = 0; break;<br \/>\ncase &#8220;Mon&#8221;: $blank = 1; break;<br \/>\ncase &#8220;Tue&#8221;: $blank = 2; break;<br \/>\ncase &#8220;Wed&#8221;: $blank = 3; break;<br \/>\ncase &#8220;Thu&#8221;: $blank = 4; break;<br \/>\ncase &#8220;Fri&#8221;: $blank = 5; break;<br \/>\ncase &#8220;Sat&#8221;: $blank = 6; break;<br \/>\n}<\/p>\n<p>\/\/We then determine how many days are in the current month<br \/>\n$days_in_month = cal_days_in_month(0, $month, $year) ;<\/p>\n<p>\/\/Here we start building the table heads<br \/>\necho &#8220;&lt;table id=wp-calendar summary=Calendar&gt;&#8221;;<br \/>\necho &#8220;&lt;CAPTION&gt;$title $year &lt;\/CAPTION&gt;&#8221;;<br \/>\necho &#8220;&lt;tr&gt;<br \/>\n&lt;TH title=Monday scope=col abbr=Monday&gt;M&lt;\/TH&gt;<br \/>\n&lt;TH title=Tuesday scope=col abbr=Tuesday&gt;T&lt;\/TH&gt;<br \/>\n&lt;TH title=Wednesday scope=col abbr=Wednesday&gt;W&lt;\/TH&gt;<br \/>\n&lt;TH title=Thursday scope=col abbr=Thursday&gt;T&lt;\/TH&gt;<br \/>\n&lt;TH title=Friday scope=col abbr=Friday&gt;F&lt;\/TH&gt;<br \/>\n&lt;TH title=Saturday scope=col abbr=Saturday&gt;S&lt;\/TH&gt;<br \/>\n&lt;TH title=Sunday scope=col abbr=Sunday&gt;S&lt;\/TH&gt;&#8221;;<\/p>\n<p>\/\/This counts the days in the week, up to 7<br \/>\n$day_count = 1;<\/p>\n<p>echo &#8220;&lt;tr&gt;&#8221;;<br \/>\n\/\/first we take care of those blank days<br \/>\nwhile ( $blank &gt; 0 )<br \/>\n{<br \/>\necho &#8220;&lt;td&gt;&lt;\/td&gt;&#8221;;<br \/>\n$blank = $blank-1;<br \/>\n$day_count++;<br \/>\n}<\/p>\n<p>\/\/sets the first day of the month to 1<br \/>\n$day_num = 1;<\/p>\n<p>\/\/count up the days, untill we&#8217;ve done all of them in the month<br \/>\nwhile ( $day_num &lt;= $days_in_month )<br \/>\n{<br \/>\nif($day_num == $day) {<br \/>\necho &#8220;&lt;td id=today&gt; $day_num &lt;\/td&gt;&#8221;;<br \/>\n} else {<br \/>\necho &#8220;&lt;td &gt; $day_num &lt;\/td&gt;&#8221;;<br \/>\n}<br \/>\n$day_num++;<br \/>\n$day_count++;<\/p>\n<p>\/\/Make sure we start a new row every week<br \/>\nif ($day_count &gt; 7)<br \/>\n{<br \/>\necho &#8220;&lt;\/tr&gt;&lt;tr&gt;&#8221;;<br \/>\n$day_count = 1;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/Finaly we finish out the table with some blank details if needed<br \/>\nwhile ( $day_count &gt;1 &amp;&amp; $day_count &lt;=7 )<br \/>\n{<br \/>\necho &#8220;&lt;td&gt; &lt;\/td&gt;&#8221;;<br \/>\n$day_count++;<br \/>\n}<\/p>\n<p>echo &#8220;&lt;\/tr&gt;&lt;\/table&gt;&#8221;;<\/p>\n<p>?&gt;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php \/\/This gets today&#8217;s date $date =time ()  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[61,60],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-php-","tag-php-calendar","tag-php-"],"_links":{"self":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=118"}],"version-history":[{"count":1,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":119,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/118\/revisions\/119"}],"wp:attachment":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}