PHP分割时间字符串

PHP分割时间字符串,php,string,date,split,regex,Php,String,Date,Split,Regex,如何拆分此字符串以获得其他5个字符串 之后,我想将它们转换为int,以便能够进行一些计算 例如: y = 2014 m = 11 d = 30 h = 21 min = 05 您可以使用strotime()将其转换为时间戳,然后使用date()提取每个变量 或者您可以将preg_match()与正则表达式一起使用,例如: /([0-9]+)\.([0-9]+)\.([0-9]+), ([0-9]+):([0-9]+)/ 这将为您提供这些值的数组。您可以在不使用的情况下创建以下函数: 有人吗?

如何拆分此字符串以获得其他5个字符串

之后,我想将它们转换为
int
,以便能够进行一些计算

例如:

y = 2014
m = 11
d = 30
h = 21
min = 05

您可以使用
strotime()
将其转换为时间戳,然后使用
date()
提取每个变量

或者您可以将
preg_match()
与正则表达式一起使用,例如:

/([0-9]+)\.([0-9]+)\.([0-9]+), ([0-9]+):([0-9]+)/

这将为您提供这些值的数组。

您可以在不使用的情况下创建以下函数:


有人吗?我尝试使用preg_match,但我不知道如何配置此。。
<?php
$date = '2014.11.30, 21:05';

function extract_date($d){
$first = explode(".", $d);
$second = explode(", ", $first[2]);
$third = explode(":", $second[1]);

$res['y'] = (int)$first[0];
$res['m'] = (int)$first[1];
$res['d'] = (int)$second[0];
$res['h'] = (int)$third[0];
$res['min'] = (int)$third[1];
return $res;
}

echo "<pre>";
print_r(extract_date($date));