sitemap)){ foreach ($site_map->sitemap as $item) { $url = str_replace($doman, __DIR__ , (string)$item->loc); $map_item = simplexml_load_file($url); foreach ($map_item->url as $elem){ $loc = str_replace($doman, $adress ,(string)$elem->loc); $itemsMap[] = array( 'loc' => $loc, 'lastmod' => (string)$elem->lastmod ); } } }else{ foreach ($site_map->url as $elem){ $loc = str_replace($doman, $adress ,(string)$elem->loc); $itemsMap[] = array( 'loc' => $loc, 'lastmod' => (string)$elem->lastmod ); } } $xml = new \SimpleXMLElement(''); foreach($itemsMap as $value){ $i = $xml->addChild('url'); $i->addChild('loc', $value['loc']); $i->addChild('lastmod', $value['lastmod']); } $dom = dom_import_simplexml($xml)->ownerDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; header('Content-Type: text/xml'); echo $dom->saveXML(); exit();