如何使用PHP动态生成XML文件?我必须在运行时动态生成XML文件。请帮助我使用PHP动态生成以下XML文件。<?xml version="1.0" encoding="UTF-8"?><xml>
<track>
<path>song1.mp3</path>
<title>Track 1 - Track Title</title>
</track>
<track>
<path>song2.mp3</path>
<title>Track 2 - Track Title</title>
</track>
<track>
<path>song3.mp3</path>
<title>Track 3 - Track Title</title>
</track>
<track>
<path>song4.mp3</path>
<title>Track 4 - Track Title</title>
</track>
<track>
<path>song5.mp3</path>
<title>Track 5 - Track Title</title>
</track>
<track>
<path>song6.mp3</path>
<title>Track 6 - Track Title</title>
</track>
<track>
<path>song7.mp3</path>
<title>Track 7 - Track Title</title>
</track>
<track>
<path>song8.mp3</path>
<title>Track 8 - Track Title</title>
</track>
3 回答

BIG阳
TA贡献1859条经验 获得超6个赞
<?php $xml = new SimpleXMLElement('<xml/>');for ($i = 1; $i <= 8; ++$i) { $track = $xml->addChild('track'); $track->addChild('path', "song$i.mp3"); $track->addChild('title', "Track $i - Track Title");}Header('Content-type: text/xml');print($xml->asXML());

桃花长相依
TA贡献1860条经验 获得超8个赞
<?php// Send the headersheader('Content-type: text/xml');header('Pragma: public');header('Cache-control: private');header('Expires: -1'); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; echo '<xml>'; // echo some dynamically generated content here /*<track> <path>song_path</path> <title>track_number - track_title</title></track>*/ echo '</xml>';?>
- 3 回答
- 0 关注
- 813 浏览
添加回答
举报
0/150
提交
取消