开发者

search for element name using PHP simple HTML dom parser

开发者 https://www.devze.com 2023-03-05 09:53 出处:网络
I\'m hoping someone can help me. I\'m using PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/manual.htm) successfully, but I now am trying to find elements based on a certain name. For

I'm hoping someone can help me. I'm using PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/manual.htm) successfully, but I now am trying to find elements based on a certain name. For example, in the fetched HTML, there might be a tags such as:

<p class="mattFacer">Matt Facer</p>
<p class="mattJones">Matt Jones</p>
<p class="daveSmith">DaveS Smith</p>

What I need to do is to read in this HTML and capture any HTML elements which match anything beginning with the word, "matt"

I've tried

$html = str_get_html("http://www.testsite.co开发者_如何学运维m");
foreach($html->find('matt*') as $element) {
   echo $element;
}

but this doesn't work. It returns nothing.

Is it possible to do this? I basically want to search for any HTML element which contains the word "matt". It could be a span, div or p.

I'm at a dead end here!


$html = str_get_html("http://www.testsite.com");
foreach($html->find('[class*=matt]') as $element) {
   echo $element;
}

Let's try that


Maybe this?

foreach(array_merge($html->find('[class*=matt]'),$html->find('[id*=matt]')) as $element) {
    echo $element;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号