How can SimpleXML be utilized to extract URLs from a sitemap in PHP?

To extract URLs from a sitemap using SimpleXML in PHP, you can load the sitemap XML file using SimpleXML, iterate through the <loc> nodes to extract the URLs, and store them in an array for further processing.

&lt;?php
// Load the sitemap XML file
$xml = simplexml_load_file(&#039;sitemap.xml&#039;);

// Initialize an array to store the URLs
$urls = [];

// Iterate through the &lt;loc&gt; nodes to extract the URLs
foreach ($xml-&gt;url as $url) {
    $urls[] = (string) $url-&gt;loc;
}

// Output the extracted URLs
print_r($urls);
?&gt;