您好,我很确定我可以找到可以解决此问题的人..
我希望从此字符串中获取值“2013 年 4 月 21 日”:
$string = "Issue Date: Sunday April 21, 2013 / week 10/2003week 11/2003week 12/2003week 13.."
提前致谢...
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'
不需要正则表达式:
$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;
如果您正在寻找首先出现的内容(在“发行日期:”之后),那么这将起作用:
Issue Date: (.*) /