Created
December 17, 2014 09:02
-
-
Save elzup/61b598d7b0aa520c1d03 to your computer and use it in GitHub Desktop.
PHPでカレンダー出力 ref: http://qiita.com/elzup/items/66a51dad716536aff159
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$col_width = 3; | |
$title_format = '-*- Y-m -*-'; | |
// 引数がない場合は今月 | |
$ts = strtotime("first day of"); | |
if (isset($argv[2])) { | |
$ts = strtotime("first day of {$argv[1]}-{$argv[2]}"); | |
} | |
list($y, $m, $t, $w) = explode(',', date('Y,m,t,w', $ts)); | |
// title | |
$title = str_replace(array('Y', 'm'), array($y, sprintf('%2d', $m)), $title_format); | |
echo str_repeat(' ', ($col_width * 7 - strlen($title)) / 2) . $title . PHP_EOL; | |
echo str_repeat(' ', $w * $col_width); | |
for ($i = 1; $i <= $t; $i++) { | |
echo sprintf("%{$col_width}d", $i); | |
if (($w + $i) % 7 == 0) { | |
echo PHP_EOL; | |
} | |
} | |
echo PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-*- 2014-12 -*- | |
1 2 3 4 5 6 | |
7 8 9 10 11 12 13 | |
14 15 16 17 18 19 20 | |
21 22 23 24 25 26 27 | |
28 29 30 31 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment