2011年1月18日 星期二

preg_match 錯誤訊息.

preg_match() [function.preg-match]: Unknown modifier '/'
記起來, 不然爾而會耍一下白吃.

原因是:
$a = 'http://xxx.xxx.xxx/xxx/';
$pattern = '|'.$a.'(\d+)|is';
preg_match( $pattern, $res, $m )

正確:變數要加 preg_quote 過濾變數.

$pattern = '|' . preg_quote($a,'/') . '(\d+)|is';
preg_match( $pattern, $res, $m )

【下列文章您可能也有興趣】

沒有留言: