2013-10-20 79 views
0

我知道有類似的問題,我已經看過他們中的一些,但即使有了這些知識,我也無法解決我自己的問題。如果有人能向我指出問題,我將不勝感激!PHP:警告:preg_match()[function.preg-match]:未知修飾符'。'在

function getCategories($source) 
{ 
    $pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*> 
<tr> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th><.tr> 
(<tr id=\".*\">\n(.*\n){6}<.td><.tr>(<.table>)?\n)*"; 

    preg_match($pattern, $source, $categories); 

    return $categories; 
} 

隨着錯誤消息:

Warning: preg_match() [function.preg-match]: Unknown modifier '.' in /home/a1464157/public_html/functions.php on line 31 

第31行是 「的preg_match(......)」。

我確定正則表達式應該可以正常工作,因爲我已經在一個工具中測試了它,並且正確的字符串肯定正在通過,它只是不喜歡我的註冊表。表達出於某種原因。我試圖確保所有內容都被轉義或被替換爲。 (逃避/不工作時最後的手段)。

任何援助將不勝感激!謝謝!

〜安德魯

回答

1

你在你的模式的每一端缺少分隔符,所以它看到這個

$pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*> 
      ^opening delimiter   ^closing delimiter followed by a modifier 

嘗試增加/作爲分隔符

$pattern = "/<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*> 
<tr> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th> 
<th.* 
<.th><.tr> 
(<tr id=\".*\">\n(.*\n){6}<.td><.tr>(<.table>)?\n)*/"; 
+0

這似乎已經擺脫了警告的,謝謝! – AndrewB

1

你應該開始和結束與一個分隔符的模式串;通常這是/,但是因爲你匹配HTML,所以選擇你明天不會使用的東西。

相關問題