Monday, September 8, 2008

Create Dynamic XML file using PHP

/* XML File name */
$filename = "evergreenphp.xml";

/* Path for XML filename */
$path_xmls = "/www/htdocs/phpdocs/missing_man";

/* File mode to Open the file */
$handle = fopen($filename, "w");

/* Sample values for the Array */
$image_array = array("1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg");

/* Writing the Header area */
$top_header = "
\n\n";
$player_list = fwrite($handle, $top_header);

/* Writing the Middle area */
for($i=0; $i < count($image_array); $i++){
$image_list = "images/".$image_array[$i]."\n";
$player_list = fwrite($handle, $image_list);
}

/* Writing the Footer area */
$bottom_footer = "
\n
";
$player_list = fwrite($handle, $bottom_footer);
fclose($handle);

/*

Output :
-------

< main>
< nodeA>
< bild>images/1.jpg
< bild>images/2.jpg
< bild>images/3.jpg
< bild>images/4.jpg
< bild>images/5.jpg
< /nodeA>
< /main>

*/
?>

No comments:

Popular Posts