I am an inexpirienced PHP'er and I need to build a script which will dynamically generate a sitemap (numbers of files on site will be updated by content providers)
I have found this script which list file names:
<?php
// Configuration
$srcPath="."; // Folder with html-files inside ("." means current folder)
function Error($text)
{
printf("Error: %s<br><br>",$text);
printf("<a href='javascript:history.back();'>Previous Page</a>");
exit();
}
class TSiteMap
{
var $filesCounter;
var $directory;
var $srcPath;
var $rowBreak;
function TSiteMap($srcPath)
{
$this->srcPath=$srcPath;
$this->ReadDirectory();
}
function ReadDirectory()
{
$directory=dir($this->srcPath);
$this->filesCounter=0;
$directory->rewind();
$directory->read(); // .
$directory->read(); // ..
$done=false;
do
{
do
{
$filename=$directory->read();
} while ($filename=="."||$filename=="..");
if (!$filename) $done=true;
else
{
$tmpPath=sprintf("%s/%s",$this->srcPath,$filename);
if (strstr($tmpPath,".htm")&&!is_dir($tmpPath))
{
$this->directory[$this->filesCounter]=$filename;
$this->filesCounter++;
}
}
} while (!$done);
$directory->close();
}
function Put()
{
for ($i=0;$i<$this->filesCounter;$i++)
{
$tmpPath=sprintf("%s/%s",$this->srcPath,$this->directory[$i]);
if (file_exists($tmpPath))
{
$linesArray=file($tmpPath);
if (count($linesArray)) $linesLinear=implode("\n",$linesArray);
else $linesLinear="";
if (strstr($linesLinear,"<meta name=\"name\" value="))
{
$tmpArray=explode("<meta name=\"name\" value=",$linesLinear);
$tmpStr=$tmpArray[1];
$tmpArray=explode(">",$tmpStr);
$name=substr($tmpArray[0],1,strlen($tmpArray[0])-2);
}
else
{
$name=$this->directory[$i];
}
}
printf("<a href='%s'>%s</a><br>",$this->directory[$i],$name);
}
}
};
$sitemap=new TSiteMap($srcPath);
printf("<html>");
printf("<head>");
printf("<title>Sitemap</title>");
printf("</head>");
printf("<body>");
printf("<b>Sitemap</b><br><br>");
$sitemap->Put();
printf("</body>");
printf("</html>");
?>
Can anyone help me add appropriate code to extract and print the contents of the title tag in the html files (e.g <title>THIS</title> will print THIS in the sitemap
Thanks
Bob