我为你做了一个片段,所以你可以从这里开始
$str = 'December 2012 Name: Jack Brown';
$ptr = "/^(?P<month>:Jan(?:uary)?|Feb(?:ruary)?|Dec(?:ember)?) (?P<year>:19[7-9]\d|2\d{3}) (Name:(?P<name>(.*)))/";
preg_match($ptr, $str, $data);
echo 'For '.trim($data['name']).' - '.$data['month'].' '.$data['year'];
结果将是
'For Jack Brown - December 2012'
这是一个数组
Array
(
[0] => December 2012 Name: Jack Brown
[month] => December
[1] => December
[year] => 2012
[2] => 2012
[3] => Name: Jack Brown
[name] => Jack Brown
[4] => Jack Brown
[5] => Jack Brown
)
我也尝试
'February 2005 Name: Bob' => 'For Bob - February 2005'
附言。你可以添加更多月份,我只是懒得添加,干杯