How can PHP be used to access content from XML files?

To access content from XML files in PHP, you can use the SimpleXML extension, which provides a simple and easy way to access and manipulate XML data. You can load an XML file using SimpleXML, navigate through its elements, and extract the desired content using various methods provided by the extension.

// Load the XML file
$xml = simplexml_load_file('data.xml');

// Access specific elements and attributes
echo $xml->book[0]->title;
echo $xml->book[1]['category'];

// Loop through elements
foreach($xml->book as $book) {
    echo $book->title . "<br>";
}