How can one execute a query on a found item using DOMXPath in PHP?

To execute a query on a found item using DOMXPath in PHP, you first need to load the HTML content into a DOMDocument object, create a DOMXPath object using the DOMDocument object, and then use the query method of the DOMXPath object to execute the query on the found item.

// Load HTML content into a DOMDocument object
$html = '<html><body><div><p>Hello World!</p></div></body></html>';
$dom = new DOMDocument();
$dom->loadHTML($html);

// Create a DOMXPath object using the DOMDocument object
$xpath = new DOMXPath($dom);

// Execute a query on a found item
$query = "//div/p";
$foundItem = $xpath->query($query);

// Loop through the found items
foreach ($foundItem as $item) {
    echo $item->nodeValue; // Output: Hello World!
}