I am trying to select the (direct) child of a parent div.element using the > combinator, but it does not work.
HTML:
<div class="element"> <p>test</p> </div> <div class="element"> <div class="selected"> <p>test2</p> </div> </div>
PHP:
$html->find('div.element > p', 0);
I want to select the direct element p .
If it is a nested descendant, it should not return anything, but returns test2 .
How can I write it to return test , but not test2 ? Thanks
UPDATE: The general consensus here regarding SO seems to be that the Simple HTML DOM is bad. I ended up writing my code using PHP DOMDocument , as Phil suggested. I really tested a win-win solution and it really worked. Thanks for the help and happy coding.
source share