2013-05-15 27 views
0

我是新來的正則表達式,真的很難讓它工作。難以讓preg_match_all工作

我想抓住從一個網頁,在下面的HTML之間的一些信息:

<!--webbot bot="Include" U-Include="/inspections/Restaurants_Avalon.html" TAG="BODY" startspan --> EVERYTHING IN BETWEEN<!--webbot bot="Include" i-checksum="41417" endspan -->

我已經試過:

$pattern = '/<.*?webbot bot=\"Include\" U-Include=\".*?\".*?startspan.*?(.*?)<.*?webbot bot=\"Include\" i-checksum=\".*?\" endspan.*?/i'; 

和一些其他的36種但是我對正規表達的明顯缺乏經驗和理解,只是造成了常規的混亂而不是表達。

有人可以看看,並告訴我我做錯了什麼?

謝謝!通過

startspan -->(.*?)<!--webbot 

startspan.*?(.*?)<.*?webbot 

在行動:

回答

0

只要改變這部分

$str = '<!--webbot bot="Include" U-Include="/inspections/Restaurants_Avalon.html" TAG="BODY" startspan --> EVERYTHING IN BETWEEN<!--webbot bot="Include" i-checksum="41417" endspan -->'; 

$pat = '/<.*?webbot bot=\"Include\" U-Include=\".*?\".*?startspan -->(.*?)<!--webbot bot=\"Include\" i-checksum=\".*?\" endspan.*?/i'; 

preg_match($pat, $str, $m); 
print_r($m); 

輸出:

Array 
(
    [0] => <!--webbot bot="Include" U-Include="/inspections/Restaurants_Avalon.html" TAG="BODY" startspan --> EVERYTHING IN BETWEEN<!--webbot bot="Include" i-checksum="41417" endspan 
    [1] => EVERYTHING IN BETWEEN 
) 
+0

沒有工作。只收到一個emtpy數組。陣列 ( [0] =>數組 ( ) [1] =>數組 ( ) ) –

+0

也試過:$圖案=「/ < - 的WebBot BOT = \ 「包含\」 U型包括= \ 「*?」 TAG = \「BODY \」startspan - >(。+?)<! - webbot bot = \「Include \」i-checksum = \「。*?\」endspan - >/is'; –

+0

剛注意到我沒有在報價前加\。添加時仍然不起作用。 –