I have this. Basically what it is doing is looping over xml files in a directory and then writing out a html file that is a merge of the xml data with a html template for each xml file in the directory.
For some reason each of the html files that it writes out is exactly the same. The data in $html is not updated every time it loops, it always has the first xml file's data. The only thing I could think of is maybe "simplexml_load_file" doesn't work when you loop over it.. maybe it is to fast to read the file correctly? Any ideas?
BTW '![title]!' is an example of a place holder I have in my html template file.
<?php
$dir = "/Library/WebServer/Documents/admin/xml/";
$files = scandir($dir);
foreach ($files as $value)
{
if (is_file("/Library/WebServer/Documents/admin/xml/$value"))
{
$xml = simplexml_load_file("/Library/WebServer/Documents/admin/xml/$value");
// breadcrumbs tweak
if ($xml->parent <> "index.php") {
$xmlparent = simplexml_load_file("/Library/WebServer/Documents/admin/xml/$xml->parent");
} else {
$xmlparent->title = 'Home';
}
// output web page
$html= File_Get_Contents('/Library/WebServer/Documents/template.html');
$find[] = '![title]!';
$find[] = '![keywords]!';
$find[] = '![body]!';
$find[] = '![parenttitle]!';
$find[] = '![parenturl]!';
$replace[] = $xml->title;
$replace[] = $xml->keywords;
$replace[] = $xml->body;
$replace[] = $xmlparent->title;
$replace[] = $xml->parenturl;
$html = str_replace($find, $replace, $html);
// this prints out the same thing every time instead of being different
echo $html;
$file = fopen("/Library/WebServer/Documents/flat/$value","wb");
fwrite($file,$html);
fclose($file);
}
}
print "done";
?>