在 php 中将月份名称转换为月份数字的简单方法


Easy way to convert the month name into month number in php

我想输入月份的全名,作为响应,我想获取月份的编号。我尝试过以下代码,当我传递"三月"作为月份名称时,它会返回我"1".有没有办法在 PHP 中获取月份的数字?

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

试试这个:

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

愿这将帮助您:)

尝试:

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