XML with PHP “echo” getting error “Extra content at the end of the document” -


i have asked question here on how generate sitemap automatically, need xml?

here solution have concluded:

<?php header ("content-type:text/xml"); echo '<?xml version="1.0" encoding="utf-8"?>     <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';         // code extract , echo links file  echo '   </urlset>'; ?>  <?php   // original php code chirp internet: www.chirp.com.au   // please acknowledge use of code including header.    $url = "assets/includes/menu.inc";   $input = @file_get_contents($url) or die("could not access file: $url");   $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";   if(preg_match_all("/$regexp/siu", $input, $matches, preg_set_order)) {     foreach($matches $match) {       // $match[2] = link address       // $match[3] = link text        echo '<url><loc>' . $match[2] . '</loc></url>';     }   } ?> 

however, when tried shows error here: http://postimg.org/image/gh5d0k4sx/ - tried remove top line "header ("content-type:text/xml");" , worked, can remove line? whole thing sake of seo don't know if can delete top line, doing wrong?

anther question: file recognized xml file? has .php extension?

your php doesn't picked browser since it's server side language.

the header function doesn't modify body of page. it's important keep in though, or browser not recognize document xml.

try removing closing , opening php tags between 2 parts of script. whitespace inbetween them may causing error.

?>  <?php 

edit: following comments, wait until output <url> tags before closing urlset

move line bottom of php:

echo '   </urlset>'; 

it's in best interests of clean xml understand how use line breaks , double quotes achieve similar effect.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -