3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<style type="text/css"> .calculator_table { font-size:12px; font-family:Century Gothic; border:2pt solid #000000; background-color:#6BB3FF padding:25px; width:300px; } </style> <?php if(!empty($_POST['calculator_ok'])): //last cycle date $date="$_POST[dateyear]-$_POST[datemonth]-$_POST[dateday]"; //convert to time $lasttime=mktime(0,0,0,$_POST['datemonth'],$_POST['dateday'],$_POST['dateyear']); // next period start $next_period=$lasttime + $_POST['days']*24*3600; $next_period=date("F d, Y",$next_period); //first fertile day $firstdaytime=$lasttime + $_POST['days']*24*3600 - 16*24*3600; $firstday=date("F d, Y",$firstdaytime); //last fertile day $lastdaytime=$lasttime + $_POST['days']*24*3600 - 12*24*3600; $lastday=date("F d, Y",$lastdaytime); //have to adjust due date? $diff=$_POST['days'] - 28; //due date $date + 280 days $duedatetime=$lasttime + 280*24*3600 + $diff*24*3600; $duedate=date("F d, Y",$duedatetime); ?> <div class="calculator_table"> <p>Here are the results based on the information you provided:</p> <p>Your next <b>menstrual period</b> is expected to start on <strong><?php echo $next_period?></strong>.</p> <p>You next <b>most fertile</b> period is <strong><?php echo $firstday?> to <?php echo $lastday?></strong>.</p> <p>If you conceive within this timeframe, your estimated <b>due date</b> will be <strong><?php echo $duedate?></strong>.</p> <p align="center"><input type="button" value="Calculate again!" onclick="window.location='http://<?php echo $_SERVER['HTTP_HOST'];?><?php echo $_SERVER['REQUEST_URI']?>'"></p> </div> <?php else: //the calculator comes here ?> <div class="calculator_table"> <form method="post"> <p>Please select the first day of your last menstrual period:</p> <p><?php echo date_chooser("date",date("Y-m-d"))?></p> <p>Usual number of days in your period: <select name="days"> <?php for($i=20;$i<=45;$i++) { if($i==28) $selected='selected="true"'; else $selected=''; echo "<option $selected value='$i'>$i</option>"; } ?> </select></p> <p align="center"><input type="submit" name="calculator_ok" value="Calculate"></p> </form> </div> <?php endif; //to print a date chooser - get name and value in mysql date format function date_chooser($name,$value="") { $months=array('','January','February','March','April','May','June','July','August', 'September','October','November','December'); if(empty($value)) $value=date("Y-m-d"); $parts=explode("-",$value); $day=$parts[2]+0; $month=$parts[1]+0; $year=$parts[0]; $chooser=""; $chooser.="<select name='".$name."month'>"; for($i=1;$i<=12;$i++) { if($i==$month) $selected='selected="true"'; else $selected=''; $chooser.="<option $selected value='$i'>$months[$i]</option>"; } $chooser.="</select> / "; $chooser.="<select name='".$name."day'>"; for($i=1;$i<=31;$i++) { if($i==$day) $selected='selected'; else $selected=''; $chooser.="<option $selected value='$i'>$i</option>"; } $chooser.="</select> / "; $chooser.="<select name='".$name."year'>"; for($i=(date("Y")-1);$i<=2050;$i++) { if($i==$year) $selected='selected'; else $selected=''; $chooser.="<option $selected>$i</option>"; } $chooser.="</select> "; return $chooser; } ?>
Output for 4.3.0 - 7.1.0
<style type="text/css"> .calculator_table { font-size:12px; font-family:Century Gothic; border:2pt solid #000000; background-color:#6BB3FF padding:25px; width:300px; } </style> <div class="calculator_table"> <form method="post"> <p>Please select the first day of your last menstrual period:</p> <p><select name='datemonth'><option value='1'>January</option><option value='2'>February</option><option value='3'>March</option><option value='4'>April</option><option value='5'>May</option><option value='6'>June</option><option value='7'>July</option><option value='8'>August</option><option selected="true" value='9'>September</option><option value='10'>October</option><option value='11'>November</option><option value='12'>December</option></select> / <select name='dateday'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option selected value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option></select> / <select name='dateyear'><option >2015</option><option selected>2016</option><option >2017</option><option >2018</option><option >2019</option><option >2020</option><option >2021</option><option >2022</option><option >2023</option><option >2024</option><option >2025</option><option >2026</option><option >2027</option><option >2028</option><option >2029</option><option >2030</option><option >2031</option><option >2032</option><option >2033</option><option >2034</option><option >2035</option><option >2036</option><option >2037</option><option >2038</option><option >2039</option><option >2040</option><option >2041</option><option >2042</option><option >2043</option><option >2044</option><option >2045</option><option >2046</option><option >2047</option><option >2048</option><option >2049</option><option >2050</option></select> </p> <p>Usual number of days in your period: <select name="days"> <option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option selected="true" value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option><option value='32'>32</option><option value='33'>33</option><option value='34'>34</option><option value='35'>35</option><option value='36'>36</option><option value='37'>37</option><option value='38'>38</option><option value='39'>39</option><option value='40'>40</option><option value='41'>41</option><option value='42'>42</option><option value='43'>43</option><option value='44'>44</option><option value='45'>45</option> </select></p> <p align="center"><input type="submit" name="calculator_ok" value="Calculate"></p> </form> </div>