My PHP code
$dom = new DOMDocument();
@$dom->loadHTML($file);
$xpath = new DOMXPath($dom);
$tags = $xpath->query('//div[@class="text"]');
foreach ($tags as $tag) {
echo $tag->textContent;
}
What I’m trying to do here is to get the content of the div that has class ‘text’ but the problem when I loop and echo the results I only get the text I can’t get the HTML code with images and all the HTML tags like p, br, img… etc i tried to use $tag->nodeValue; but also nothing worked out.
Personally, I like Simple HTML Dom Parser.
Pretty simple, huh? It accommodates selectors like jQuery 🙂