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. Quote Link to comment 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. Quote Link to comment 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". Quote Link to comment 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). Quote Link to comment 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.