php - simple_html_dom find all elements that ONLY contain certain text -


i have:

 <span>something or other</span>  <b>blarg</b>  <b>blarg , stuff</b>  <span>blarg</span>  <em>wakka wakka</em>  <em>wakka blarg</em>  <em>blarg</em> 

and want elements contain "blarg" , no other text, so:

 <b>blarg</b>  <span>blarg</span>  <em>blarg</em>  

the important issue here i'm trying check if blarg exists within 1 element alone on page or not. i've had general luck regex i'd rather simple_html_dom can @ child , sibling elements well.

does know simplest way simple_html_dom?

a way it, parse every tag, , test if contains 'blarg'...

here's working example:

$text = '<span>something or other</span>  <b>blarg</b>  <b>blarg , stuff</b>  <span>blarg</span>  <em>wakka wakka</em>  <em>wakka blarg</em>  <em>blarg</em>';  echo  "<div>original text: <xmp>$text</xmp></div>";  $html = str_get_html($text);  // find elements $tags = $html->find('*');  foreach ($tags $key => $tag) {     // if text in tag contains 'blarg'     if (strcmp(trim($tag->plaintext),'blarg') == 0) {         echo  "<div> 'blarg' found in \$tags[$key]: <xmp>".$tag->outertext."</xmp></div>";     } } 

i don't know want with, may start :)


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -