我的表情不太好......我看過一些在線教程,但我仍然沒有得到它。基本上,我試圖返回TRUE
如果一個字符串的格式如下:PHP - preg_match?
4位數字+空格+ 2位數並將其轉換爲日期。
所以,字符串看起來像:2010 02
,我試圖輸出February, 2010
。
我試圖使用preg_match
,但我不斷收到
{ is not a modifier...
編輯
每第2個反應,我改變了它,但我第一個得到一個致命的錯誤,在第二個相同的未知修飾符錯誤:
if(preg_match('/([0-9{4}]) ([0-9]{2})/iU',$path_part)) {
$path_title = date("F, Y",strtotime(str_replace(" ","-", $path_title)));
}
此外,只是嘗試更深入的杉木版本ST響應,同時錯誤消失,它不會改變輸出...
$path_part = '2010 02';
if(preg_match('/^(\d{4}) (\d{2})$/',$path_part,$matches)) {
$path_title = $mon[(int)$matches[2]] . " " . $matches[1]; // prints Feb 2010
}
/([0-9 {4}])([0-9] {2})/是不正確。使用/([0-9] {4})([0-9] {2})/或 /(\ d {4})(\ d {2})/ – codaddict 2010-02-07 15:57:35