How can PHP be used to extract multiple XML attributes?

To extract multiple XML attributes using PHP, you can use the SimpleXMLElement class to parse the XML data and access the attributes using array syntax. You can loop through the attributes to extract and display their values.

$xml = '<bookstore>
  <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
  </book>
</bookstore>';

$books = new SimpleXMLElement($xml);

foreach ($books->book as $book) {
    $category = $book['category'];
    $title = $book->title['lang'];
    
    echo "Category: $category, Title Language: $title <br>";
}