How can XPath be used in PHP to search for specific elements in an XML document?

To search for specific elements in an XML document using XPath in PHP, you can use the `DOMXPath` class along with `DOMDocument`. First, load the XML document into a `DOMDocument` object, then create a new `DOMXPath` object to query the document using XPath expressions. You can use XPath expressions to select specific elements based on their tag name, attributes, or other criteria.

// Load the XML document
$xml = new DOMDocument();
$xml->load('example.xml');

// Create a new DOMXPath object
$xpath = new DOMXPath($xml);

// Use XPath to search for specific elements
$elements = $xpath->query('//book[author="John Doe"]');

// Loop through the results
foreach ($elements as $element) {
    echo $element->nodeValue . "\n";
}