Question

I am using the simple_html_dom parser and I want to fetch data from html code that looks like this:

<pre class="root">
     <span class="B bgB"></span>
     <span class="B bgB"></span>
     <span class="B bgB"></span>
     <span class="B bgB"></span>
     <span class="W"></span>
     <span class="Y DH"> </span>
     <span class="Y DH">Some text</span>
</pre>

etc..

But I only want to get the content from the ones without the bgB class. So far I have this code:

$elements = $html->find('pre.root span[class!=bgB]');

But all spans are fetched and later printed, not only the ones without the bgB class. How can I accomplish this?

Was it helpful?

Solution

It can't be done with simple but if you switch to this one you can use the css :not pseudo:

$html = str_get_html($str);
$elements = $html->find('pre.root span:not(.bgB)');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top