我看過其他問題,關於如何解析日期到星期幾,硬編碼到代碼中的日期,但是我怎樣才能從一個表單發佈到自身?基本上有兩個下拉菜單(一個月和一個日期)和一個字段進入一年。我無法弄清楚如何將這三個字段放入一個$日期,然後使用echo date('l', strtotime($date));
來顯示它。 每日轉換器
<?php
session_start();
if(!isset($_SESSION['month'])){
$_SESSION['month']= 01;
}
$month = $_SESSION['month'];
if(isset($_POST['month'])){
$month = $_POST['month'];
}
if(!isset($_SESSION['day'])){
$_SESSION['day']= 01;
}
$day = $_SESSION['day'];
if(isset($_POST['day'])){
$day = $_POST['day'];
}
if(!isset($_SESSION['year'])){
$_SESSION['year']= 0000;
}
$year = $_SESSION['year'];
if(isset($_POST['year'])){
$year = $_POST['year'];
}
if(!isset($_SESION['date'])){
$_SESSION['date'] = 'month'.'/'.'day'.'/'.'year';
}
$date = $_SESSION['date'];
if(isset($_POST['date'])){
$date= $_POST['date'];
}
if(!isset($_SESION['date'])){
$_SESSION['date'] = $month.$day.$year;
}
$date = $_SESSION['date'];
if(isset($_POST['date'])){
$date= $_POST['date'];
}
echo date('l', strtotime($date));
session_destroy();
?>
我的形式是在這裏:
所有的<body>
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="POST">
<fieldset>
<legend>Date to Day Converter</legend>
Month:<br>
<select name="month">
<option value=01>January</option>
<option value=02>February</option>
<option value=03>March</option>
<option value=04>April</option>
<option value=05>May</option>
<option value=06>June</option>
<option value=07>July</option>
<option value=08>August</option>
<option value=09>September</option>
<option value=10>October</option>
<option value=11>November</option>
<option value=12>December</option>
</select>
<br>
Day:<br>
<select name="day">
<option value=01>01</option>
<option value=02>02</option>
<option value=03>03</option>
<option value=04>04</option>
<option value=05>05</option>
<option value=06>06</option>
<option value=07>07</option>
<option value=08>08</option>
<option value=09>09</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 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>
<br>
Year:<br>
<input type="text" name"year">
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
是什麼你已經發布的代碼給你? – chris85 2015-04-02 21:29:14
我輸入的任何日期,它告訴我星期三 – TonyPall 2015-04-02 21:32:51
如果你回聲'$ date'是否正確? – chris85 2015-04-02 21:44:40