How to parse an xml sitemap using PHP and Curl

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36');
$resp = curl_exec ($ch);

$xml = new SimpleXMLElement($resp);

foreach ($xml->url as $url_list) {

    $url = $url_list->loc;
    echo $url . "<br />";


curl_close ($ch);

Leave a Comment

Your email address will not be published. Required fields are marked *