I am having trouble writing my file directory of my website in to an XML file. I've searched all over google and have had no success with the examples that I've found. I've checked the php documentation but can't find anything really.
here's the code i've been working with:
PHP Code:
$contents = "<?xml version=\"1.0\" ?>\n";
$path = "easythanks/";
function outputPath($path){
$level=substr_count($path,'/');
for ($i=1;$i<$level;$i++) echo ' ';
echo basename($path);
echo "\n";
}
echo '<pre>';
traverseDirTree('./','outputpath','outputpath');
echo '</pre>';
function traverseDirTree($base,$fileFunc,$dirFunc=null,$afterDirFunc=null){
$subdirectories=opendir($base);
while (($subdirectory=readdir($subdirectories))!==false){
$path=$base.$subdirectory;
if (is_file($path)){
$contents .= "<item text=".$path." />";
if ($fileFunc!==null){
$fileFunc($path);
}
}else{
$contents .= "<item text=".$path.">";
if ($dirFunc!==null) $dirFunc($path);
if (($subdirectory!='.') && ($subdirectory!='..')){
traverseDirTree($path.'/',$fileFunc,$dirFunc,$afterDirFunc);
}
if ($afterDirFunc!==null) $afterDirFunc($path);
$contents .= "</item>";
}
}
}
$myFile = "test.xml";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $contents);
fclose($fh);
Can anyone please point me in the right direction? PS the xml file needs to look like this
Code:
<item text="directory1">
<item text="directory2">
<item text="child1" />
</item>
<item text="child2" />
<item text="child3"/>
</item>
Thanks,
David