i got a question i got a working xml sitemap generation script in php.the entries are generated over a foreach loop through directories. but i need to do it for an .txt file in this way. Split the entries in the .txt file and create a for each loop for every line in .txt file in order to generate the xml sitemap.
this way looks my .txt file:
"value1"
"value2"
"value3"
etc.
Here is the Sitemap Generator script, how can i split the .txt the right way to make it work in the for each Loop. Please need some advice or help would be really great.
<?php
$directory = "pictures/".$_GET['social']."/".$_GET['cat']."/";
$filecount = 0;
$files = glob($directory . "*");
if ($files){
$filecount = count($files);
}
//Where to put in .txt file read and split it here?
header("Content-Type: text/xml");
function xmlentities($text)
{
$search = array('&','<','>','"','\'');
$replace = array('&','<','>','"',''');
return str_replace($search,$replace,$text);
}
print chr(60)."?xml version='1.0' encoding='UTF-8'?".chr(62);
print chr(60)."urlset xmlns='http://www.google.com/schemas/sitemap/0.84' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd'".chr(62);
//here foreach for every line in .txt file?
foreach (array_slice(glob("pictures/".$_GET['social']."/".$_GET['cat']."/*"), 0, $filecount) as $filename) {
$data = getimagesize(str_replace("bilder/thumbs","bilder", $filename));
$width = $data[0];
$height = $data[1];
$extension = image_type_to_extension($data[2]);
$imgsize = filesize(str_replace("bilder/thumbs","bilder", $filename));
$fileextension = substr($filename, -3);
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename);
// create the loc (URL) value based on the foreach loop value, from txt:
$loc = "https://www.dp-pics.com/".$_GET['social']."/".$_GET['cat']."/".$fileextension."/".lcfirst(basename($withoutExt)).".html";
print "<url>";
print "<loc>".xmlentities($loc)."</loc>";
print "</url>";
}
print "</urlset>";
?>