-4

您好,我很确定我可以找到可以解决此问题的人..

我希望从此字符串中获取值“2013 年 4 月 21 日”:

$string = "Issue Date: Sunday April 21, 2013 / week 10/2003week 11/2003week 12/2003week 13.."

提前致谢...

4

3 回答 3

2

preg_match()与以下正则表达式一起使用/^Issue Date: [A-z]+ (.*) \//

// prepare string and pattern
$string = 'Issue Date: Sunday April 21, 2013 / week 10/2003week 11/2003week 12/2003week 13..';
$pattern = '/^Issue Date: [A-z]+ (.*) \//';

// exec regex and check for results
if(!preg_match($pattern, $string, $matches)) {
    die('the pattern was not found');
}

// output the results:
$date = $matches[1];
echo $date; // output: 'April 21, 2013'
于 2013-04-22T02:42:49.490 回答
2

不需要正则表达式:

$string = 'Issue Date: Sunday April 21, 2013 / week 10/2003week 11/2003week 12/2003week 13..';
$array = explode(' ',$string);
$date = $array[3] . ' ' . $array[4] . ' ' . $array[5];
echo $date;
于 2013-04-22T02:47:09.357 回答
1

如果您正在寻找首先出现的内容(在“发行日期:”之后),那么这将起作用:

Issue Date: (.*) /

于 2013-04-22T02:41:53.207 回答