konratnox
3/20/2018 - 7:22 AM

Generate sitemap.xml

Script generates sitemap.xml from array

example of url

https://en.city.rent/ofisi/

if(count($arXml)) {
        $doc = new DOMDocument('1.0', 'UTF-8');
        $doc->formatOutput = true;
        
        $root = $doc->createElement('urlset');
        $root = $doc->appendChild($root);
        
        $attr = $doc->createAttribute('xmlns');
        $attr->value = 'http://www.sitemaps.org/schemas/sitemap/0.9';
        $root->appendChild($attr);
        
        
        foreach($arXml as $value) {
            $thumb = $doc->createElement('url');
            $thumb = $root->appendChild($thumb);
            
            $em = $doc->createElement('loc');
            $list = $thumb->appendChild($em);
            
            $text = $doc->createTextNode($value);
            $em->appendChild($text);
        }
        $doc->normalize();
        $doc->save($_SERVER['DOCUMENT_ROOT'].'/sitemap.xml');
    
    }