Search code examples
phpxmlglob

How to display php output as xml


I have this simple php that outputs a list of all the png files in a directory. Is there a way to take this list and make it xml?

<?php
foreach (glob("*.png") as $filename) {
    echo "$filename " ;
}
?>

Solution

  • Depends on the format of XML that you want. This would work:

    <?xml version="1.0" encoding="UTF-8"?>
    <?php
    foreach (glob("*.png") as $filename) {
        echo "<png>$filename</png>";
    }
    ?>