How to make xml out from text inside a text file in php?
I have a code but it brings me error "Extra content at the end of the document".
Below is my code:
<?php
header('Content-Type: application/xml');
$lines = file('file.txt');
echo '<?xml version="1.0" encoding="UTF-8"?>';
foreach($lines as $line){
$output = '<url><loc>http://example.com/'.$line.'.html</loc></url>';
echo $output;
}
here is example text file:
page1
page2
page3
page4
sample output:
<url>
<loc>http://example.com/page1.html</loc>
</url>
<url>
<loc>http://example.com/page2.html</loc>
</url>
<url>
<loc>http://example.com/page3.html</loc>
</url>
<url>
<loc>http://example.com/page4.html</loc>
</url>
I will need to use these for sitemap.xml