2016-03-01 90 views
0

我想輸入月份的全名,並作爲迴應我想獲得月份的編號。 我已經嘗試過下面的代碼,當我通過「3月」作爲月份名稱它返回我「1」.is有任何方法來獲取月份的數字在PHP?簡單的方法將月份名稱轉換爲月份編號在php

$month_number = date('n', strtotime($string)); 
+0

該代碼返回 「1」 爲已到達一月或_any無法識別string_成'strtotime'。如果我將「March」作爲'$ string'傳遞給您的代碼,它會成功返回「3」。 –

回答

0

試試這個:

<?php 
    $date = date_parse('March'); 
    echo($date['month']); 
?> 

也許這將幫助你:)

0

嘗試:

date('m', strtotime("March")); 
+0

儘管此代碼可能會回答問題,但提供關於此代碼爲何和/或如何回答問題的其他上下文可提高其長期價值。 –

相關問題