2012-11-17 40 views
1

我怎麼能 「找到」 這些ID的所有元素髮現的元素:正則表達式在PHP簡單的HTML DOM解析器

ctl00_cphContent_ctl05_Panel01,

ctl00_cphContent_ctl06_Panel01,

ctl00_cphContent_ctl07_Panel01,

ctl00_cphContent_ctl08_Panel01 , 等...

我試圖

foreach($html->find('a#ctl00_cphContent_ctl'.*.'_Panel01') as $positions) { echo "Test!";} 

但它不工作!有人能幫助我嗎?我搜索但沒有找到類似的東西...

回答

2

從閱讀簡單的HTML DOM解析文檔http://simplehtmldom.sourceforge.net/manual.htm#section_find,我不認爲它包含完整的正則表達式功能。但它似乎有基本匹配。試試這個:

$html->find('[id^=ctl00_cphContent_ctl]') 

顯然,這不會只是匹配ID標籤,如ctl00_cphContent_ctl05_Panel01,而且會匹配ctl00_cphContent_ctrandomstuffhere事情。但似乎沒有可能以您想要的方式進行完整的正則表達式匹配。

+0

無論如何非常感謝! :d – Alexandros