sleazyfish Posted November 19, 2010 Share Posted November 19, 2010 Hi, This script lists all the contents of the dir it is placed in bar itself. Perfect for what I need. However, I want to output the results as xml and being new to php I really don't know where to start. <?php foreach (new DirectoryIterator('.') as $file) { if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) { echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename(); } } ?> I'd be thankful for the help Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/219167-how-do-i-output-this-php-as-xml/ Share on other sites More sharing options...
salathe Posted November 19, 2010 Share Posted November 19, 2010 Please give an example of the XML that you would like to output. Link to comment https://forums.phpfreaks.com/topic/219167-how-do-i-output-this-php-as-xml/#findComment-1136505 Share on other sites More sharing options...
sleazyfish Posted November 19, 2010 Author Share Posted November 19, 2010 Sorry I should have thought to post an example in my original query. This would be to desired format: <?xml version="1.0" encoding="UTF-8" ?> - <images> <image>file1</image> <image>file2</image> <image>file3</image> <image>file4</image> <image>file5</image> </images> If possible i would prefer the output to exclude the extension of the file e.g "file1.jpg" becomes just "file1". Link to comment https://forums.phpfreaks.com/topic/219167-how-do-i-output-this-php-as-xml/#findComment-1136508 Share on other sites More sharing options...
salathe Posted November 19, 2010 Share Posted November 19, 2010 There are many ways of writing XML in PHP, could you take a look over some and see which you like most. For your needs, they're all about as easy to get started with as each other. So, for reference: Document Object Model (DOM) http://php.net/dom SimpleXML http://php.net/simplexml XML Writer http://php.net/xmlwriter And for getting the file name without the extension, you could a) get the file extension, then b) use $file->getBasename($ext). Link to comment https://forums.phpfreaks.com/topic/219167-how-do-i-output-this-php-as-xml/#findComment-1136527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.