Preg_replace:转换字符串日期格式

时间:2013-01-21 17:28:12

标签: php preg-replace substring

我使用diff strpos()substr()获取大数组:

$array[n] = ('Jan 23', 'From Jan 4 to Feb 1', 'Jul 5 to 10');

我希望有一个过程将其转换为:

$array[n] = ('2013-01-23','2013-01-04/2013-02-01','2013-07-05/2013-07-10);

感谢您的帮助。 我计划使用strpos()将日期字符串放入数组中。 之后,我计划爆炸日期数组,然后执行foreach($date as $index => $value),如果我可以将它转换为字符串然后它是一个日期,我可以使用两位数,与月份名称匹配数月。然后形成所需的字符串。

有更好的解决方案吗?

1 个答案:

答案 0 :(得分:2)

为什么不使用strtotime()函数和date_format()函数?使用正则表达式和字符串解析处理所有可能的格式可能非常困难。

date('Y-m-d', strtotime('your_string'));