okuden-labo
3/18/2015 - 3:28 AM

厄年表示プログラム

厄年表示プログラム

//もっとシンプルな書き方があるんですが。私の実力不足です…

<?php
   setlocale(LC_TIME, "ja_JP.utf8", "Japanese_Japan.932");
   $y1 = strtotime("-60 year");
   $y1_be = strtotime("-59 year");
   $y1_af = strtotime("-61 year");
   $y2 = strtotime("-41 year");
   $y2_be = strtotime("-40 year");
   $y2_af = strtotime("-42 year");
   $y3 = strtotime("-24 year");
   $y3_be = strtotime("-23 year");
   $y3_af = strtotime("-25 year");
   $y4 = strtotime("-36 year");
   $y4_be = strtotime("-35 year");
   $y4_af = strtotime("-37 year");
   $y5 = strtotime("-32 year");
   $y5_be = strtotime("-31 year");
   $y5_af = strtotime("-33 year");
   $y6 = strtotime("-18 year");
   $y6_be = strtotime("-17 year");
   $y6_af = strtotime("-19 year");

   $w1 = strftime('%EC%Ey年', $y1);
   $w2 = strftime('%EC%Ey年', $y2);
   $w3 = strftime('%EC%Ey年', $y3);
   $w4 = strftime('%EC%Ey年', $y4);
   $w5 = strftime('%EC%Ey年', $y5);
   $w6 = strftime('%EC%Ey年', $y6);
   $w1_be = strftime('%EC%Ey年', $y1_be);
   $w1_af = strftime('%EC%Ey年', $y1_af);
   $w2_be = strftime('%EC%Ey年', $y2_be);
   $w2_af = strftime('%EC%Ey年', $y2_af);
   $w3_be = strftime('%EC%Ey年', $y3_be);
   $w3_af = strftime('%EC%Ey年', $y3_af);
   $w4_be = strftime('%EC%Ey年', $y4_be);
   $w4_af = strftime('%EC%Ey年', $y4_af);
   $w5_be = strftime('%EC%Ey年', $y5_be);
   $w5_af = strftime('%EC%Ey年', $y5_af);
   $w6_be = strftime('%EC%Ey年', $y6_be);
   $w6_af = strftime('%EC%Ey年', $y6_af);

   $e1 = date("Y",$y1);
   $e2 = date("Y",$y2);
   $e3 = date("Y",$y3);
   $e4 = date("Y",$y4);
   $e5 = date("Y",$y5);
   $e6 = date("Y",$y6);
   $e1_be = date("Y",$y1_be);
   $e1_af = date("Y",$y1_af);
   $e2_be = date("Y",$y2_be);
   $e2_af = date("Y",$y2_af);
   $e3_be = date("Y",$y3_be);
   $e3_af = date("Y",$y3_af);
   $e4_be = date("Y",$y4_be);
   $e4_af = date("Y",$y4_af);
   $e5_be = date("Y",$y5_be);
   $e5_af = date("Y",$y5_af);
   $e6_be = date("Y",$y6_be);
   $e6_af = date("Y",$y6_af);

   $eto = array("さる","とり","いぬ","いのしし","ねずみ","うし","とら","うさぎ","たつ","へび","うま","ひつじ");
 ?>

 <h2>厄除け早見表(<?php print(strftime("%EC%Ey")); ?>年度)</h2>

<p>【男性】</p>
<table class="hayami">
  <tbody>
    <tr>
      <th>前厄</th>
      <td>24歳 <?php echo $eto[$e3_be%12]; ?>
        <br />(<?php echo $w3_be; ?>生)</td>
      <td>41歳 <?php echo $eto[$e2_be%12]; ?>
        <br />(<?php echo $w2_be; ?>生)</td>
      <td>60歳 <?php echo $eto[$e1_be%12]; ?>
        <br />(<?php echo $w1_be; ?>生)</td>
    </tr>
    <tr>
      <th>本厄</th>
      <td>25歳 <?php echo $eto[$e3%12]; ?>
        <br />(<?php echo $w3; ?>生)</td>
      <td>42歳 <?php echo $eto[$e2%12]; ?>
        <br />(<?php echo $w2; ?>生)</td>
      <td>61歳 <?php echo $eto[$e1%12]; ?>
        <br />(<?php echo $w1; ?>生)</td>
    </tr>
    <tr>
      <th>後厄</th>
      <td>26歳 <?php echo $eto[$e3_af%12]; ?>
        <br />(<?php echo $w3_af; ?>生)</td>
      <td>43歳 <?php echo $eto[$e2_af%12]; ?>
        <br />(<?php echo $w2_af; ?>生)</td>
      <td>62歳 <?php echo $eto[$e1_af%12]; ?>
        <br />(<?php echo $w1_af; ?>生)</td>
    </tr>
  </tbody>
</table>
<p>【女性】</p>
<table class="hayami">
  <tbody>
    <tr>
      <th>前厄</th>
      <td>18歳 <?php echo $eto[$e6_be%12]; ?>
        <br />(<?php echo $w6_be; ?>生)</td>
      <td>32歳 <?php echo $eto[$e5_be%12]; ?>
        <br />(<?php echo $w5_be; ?>生)</td>
      <td>36歳 <?php echo $eto[$e4_be%12]; ?>
        <br />(<?php echo $w4_be; ?>生)</td>
    </tr>
    <tr>
      <th>本厄</th>
      <td>19歳 <?php echo $eto[$e6%12]; ?>
        <br />(<?php echo $w6; ?>生)</td>
      <td>33歳 <?php echo $eto[$e5%12]; ?>
        <br />(<?php echo $w5; ?>生)</td>
      <td>37歳 <?php echo $eto[$e4%12]; ?>
        <br />(<?php echo $w4; ?>生)</td>
    </tr>
    <tr>
      <th>後厄</th>
      <td>20歳 <?php echo $eto[$e6_af%12]; ?>
        <br />(<?php echo $w6_af; ?>生)</td>
      <td>34歳 <?php echo $eto[$e5_af%12]; ?>
        <br />(<?php echo $w5_af; ?>生)</td>
      <td>38歳 <?php echo $eto[$e4_af%12]; ?>
        <br />(<?php echo $w4_af; ?>生)</td>
    </tr>
  </tbody>
</table>