fork download
  1. <?php
  2. // 当月1日
  3. $start = new DateTime();
  4. $start->modify('first day of this months');
  5. // 当月末日
  6. $end = new DateTime();
  7. $end->modify('last day of this months');
  8. $week = array(
  9. 0 => array('name' => '日', 'class' => 'sun'),
  10. 1 => array('name' => '月', 'class' => 'std'),
  11. 2 => array('name' => '火', 'class' => 'std'),
  12. 3 => array('name' => '水', 'class' => 'std'),
  13. 4 => array('name' => '木', 'class' => 'std'),
  14. 5 => array('name' => '金', 'class' => 'std'),
  15. 6 => array('name' => '土', 'class' => 'sat'),
  16. );
  17. ?>
  18. <!DOCTYPE html>
  19. <html>
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  22. <title></title>
  23. <style>
  24. .sun {
  25. color: #F00;
  26. }
  27. .std {
  28. color: #000;
  29. }
  30. .sat {
  31. color: #00F;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <table>
  37. <tr>
  38. <?php foreach (array_column($week, 'name') as $w_name): ?>
  39. <td><?= $w_name;?></td>
  40. <?php endforeach; ?>
  41. </tr>
  42. <?php do{ ?>
  43. <tr>
  44. <?php
  45. foreach (array_column($week, 'class') as $w_k => $w_class):
  46. if ($start->format('w') != $w_k) {
  47. $d = '&nbsp;';
  48. $class = '';
  49. } else {
  50. $d = $start->format('d');
  51. $class = ' class="' . $w_class . '"';
  52. $start->modify('+1 days');
  53. }
  54. ?>
  55. <td<?= $class;?>><?= $d;?></td>
  56. <?php
  57. if ($start >= $end) {
  58. break;
  59. }
  60. endforeach;
  61. ?>
  62. </tr>
  63. <?php } while ($start >= $end); ?>
  64. </table>
  65. </body>
  66. </html>
  67.  
Success #stdin #stdout 0.01s 83904KB
stdin
Standard input is empty
stdout
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <style>
            .sun {
                color: #F00;
            }
            .std {
                color: #000;
            }
            .sat {
                color: #00F;
            }
        </style>
    </head>
    <body>
        <table>
            <tr>
                                <td>日</td>
                                <td>月</td>
                                <td>火</td>
                                <td>水</td>
                                <td>木</td>
                                <td>金</td>
                                <td>土</td>
                            </tr>
                        <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td class="std">01</td>
                                <td class="std">02</td>
                                <td class="sat">03</td>
                            </tr>
                    </table>
    </body>
</html>