tryingtolearn Posted December 14, 2010 Share Posted December 14, 2010 I have a function which is listing my directories w/ files (Images) in them. <?php function sortDirectory($path = 'images') { $ignore = array('.', '..', 'index.php'); $folder = array(); $dh = @opendir($path); while (false !== ( $file = readdir($dh) )) { if (!in_array($file, $ignore)) { if (is_dir("$path/$file")) { $folder[$file] = sortDirectory("$path/$file"); } else { $folder[$file] = "$path/$file"; } } } closedir($dh); ksort($folder); return $folder; } function getDirectory($folder = array(),$level = 0) { // Set which extensions should be approved in the XML file $extensions = array( 'jpg', 'JPG', 'png', 'PNG', 'gif', 'GIF', 'bmp', 'BMP'); $spaces = str_repeat(' ', ( $level * 4)); foreach($folder as $file=>$path) { if (is_array($path)) { echo "<strong>$spaces $file</strong><br />"; getDirectory($path, $level+1); } else { if ( in_array( substr($file, -3), $extensions ) ){ echo "$spaces <a href=\"$path\">$file</a><br />"; } } } } getDirectory(sortDirectory()); ?> Im trying to get it to write an xml file in this fashion <?xml version="1.0" encoding="utf-8" standalone="yes"?> <dir1> <pic> <image>file1.jpg</image> </pic> <pic> <image>file2.jpg</image> </pic> </dir1> <dir2> <pic> <image>file1.jpg</image> </pic> <pic> <image>file2.jpg</image> </pic> </dir2> but I cannot seem to get a grasp on this simplexml for more than 1 directory - any help appreciated.? Quote Link to comment https://forums.phpfreaks.com/topic/221609-output-dir-to-xml/ Share on other sites More sharing options...
RichardRotterdam Posted December 14, 2010 Share Posted December 14, 2010 Can't you just replace the html tags with xml tags? And do you need to save this xml to disk as an xml file? Quote Link to comment https://forums.phpfreaks.com/topic/221609-output-dir-to-xml/#findComment-1147104 Share on other sites More sharing options...
tryingtolearn Posted December 14, 2010 Author Share Posted December 14, 2010 Can't you just replace the html tags with xml tags? Guess I could, figured there might be a better way to do it. The html tags were just to make it easier to make sure I was getting the results I wanted. And do you need to save this xml to disk as an xml file? Yes Quote Link to comment https://forums.phpfreaks.com/topic/221609-output-dir-to-xml/#findComment-1147366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.