你好,我敢肯定,我可以找到誰可以解決這個..PHP/Regex如何獲取此字符串的值?
我希望得到「2013年4月21日」數值超出此字符串:提前
$string = "Issue Date: Sunday April 21, 2013/week 10/2003week 11/2003week 12/2003week 13.."
感謝。 ..
你好,我敢肯定,我可以找到誰可以解決這個..PHP/Regex如何獲取此字符串的值?
我希望得到「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'
如果你(在 「簽發日期」)找什麼首先出現,那麼這將工作:
Issue Date: (.*) /
無需正則表達式:|:(。*?)
$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;
'發行日期/ |'應該工作 – Blender 2013-04-22 02:40:39
我想: 的preg_match( 「#發起日期:(。*)/#」,$ string,$ matches);然後通過空間爆炸比賽..但這是一個不錯的選擇 – Sebastian 2013-04-22 02:40:54