Finding an element name with a simple PHP HTML parser

I hope someone can help me. I am using PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/manual.htm) successfully, but now I am trying to find elements based on a specific name. For example, the selected HTML may contain 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 read in this HTML and grab any HTML elements that match anything, starting with the word "matte"

I tried

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

but it does not work. It does not return anything.

Can this be done? I basically want to search for any HTML element containing the word "matte". It can be span, div or p.

I'm here in a dead end!

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

Try that

+3
source

Maybe this?

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

All Articles