regexp on finding elements in PHP Simple HTML DOM Parser

廉价感情. 提交于 2020-01-14 03:45:28

问题


How can i "find" all elements with those id:

ctl00_cphContent_ctl05_Panel01,

ctl00_cphContent_ctl06_Panel01,

ctl00_cphContent_ctl07_Panel01,

ctl00_cphContent_ctl08_Panel01, etc...

I tried

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

But it doesn't work! Can someone help me please? I search but didn't find something similar...


回答1:


From reading the simple HTML DOM parses documentation http://simplehtmldom.sourceforge.net/manual.htm#section_find, I don't think that it includes full regex functionality. However it does seem to have basic matching. Try this:

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

Obviously this wont just match id tags like ctl00_cphContent_ctl05_Panel01, but will also match things like ctl00_cphContent_ctrandomstuffhere. But it doesn't appear to be possible to do a full regexp match in the way you want.



来源:https://stackoverflow.com/questions/13429755/regexp-on-finding-elements-in-php-simple-html-dom-parser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!