How can PHP be used to parse and evaluate data from a webpage using DOMDocument?
To parse and evaluate data from a webpage using DOMDocument in PHP, you can load the webpage content into a DOMDocument object and then use XPath queries to extract specific elements or data from the webpage.
<?php
// Load the webpage content into a DOMDocument object
$doc = new DOMDocument();
$doc->loadHTMLFile('http://example.com/page');
// Use XPath queries to extract specific elements or data
$xpath = new DOMXPath($doc);
$elements = $xpath->query('//div[@class="content"]');
// Loop through the extracted elements and do something with them
foreach ($elements as $element) {
echo $element->nodeValue . "\n";
}
?>