在PHP简单HTML DOM解析器中查找元素的正则表达式 [英] regexp on finding elements in PHP Simple HTML DOM Parser

查看:174
本文介绍了在PHP简单HTML DOM解析器中查找元素的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何找到"相关信息?所有具有这些ID的元素:

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

ctl00_cphContent_ctl05_Panel01,

ctl00_cphContent_ctl05_Panel01,

ctl00_cphContent_ctl06_Panel01,

ctl00_cphContent_ctl06_Panel01,

ctl00_cphContent_ctl07_Panel01,

ctl00_cphContent_ctl07_Panel01,

ctl00_cphContent_ctl08_Panel01, 等等...

ctl00_cphContent_ctl08_Panel01, etc...

我尝试过

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...

推荐答案

从阅读简单的HTML DOM解析文档开始

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]' )

很显然,这将不匹配ID标记(例如ctl00_cphContent_ctl05_Panel01),但也将匹配ctl00_cphContent_ctrandomstuffhere之类的东西.但是似乎无法按照您想要的方式进行完整的正则表达式匹配.

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.

这篇关于在PHP简单HTML DOM解析器中查找元素的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆