Reputation: 134
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 " ;
}
?>
Upvotes: 0
Views: 194
Reputation: 60516
Render it manually?
<?php
$xmlStr = '<?xml version="1.0" ?><directory>';
foreach (glob("*.png") as $filename) {
$xmlStr .= '<file>' . $filename . '</file>';
}
$xmlStr .= '</directory>';
header('Content-type: text/xml');
echo $xmlStr;
?>
Upvotes: 1
Reputation: 17960
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>";
}
?>
Upvotes: 2