I have below scenarios of $html contents. I want to check if html content is start with a media (image or video, iframe) without any text content like 3rd scenario.
//no contetn between first p tag and image tag
$html = '<p dir="ltr"><img src="imageurl" class="img"><br></p>
<div>some content </div>';
//no content between first p tag and video tag
$html = '<p dir="ltr"><video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video></p>
<div>some content </div>';
//having content inside first p tag
$html = '<p dir="ltr">here we have text<img src="imageurl" class="img"><br></p>
<div>some content </div>';
I have tried like this but no luck, please advice
$dom = new DOMDocument();
$dom->loadHTML($html);//that's HTML of my document, string
$xpath = new DOMXPath($dom);
$xpath_resultset = $xpath->query("p/following-sibling::node()[not(preceding-sibling::img) and not(self::img)]");