How to generate XML file dynamically using PHP?

前端 未结 7 2265
失恋的感觉
失恋的感觉 2020-11-22 00:32

I have to generate a xml file dynamically at runtime. Please help me in generating the below XML file dynamically using PHP.



        
7条回答
  •  梦如初夏
    2020-11-22 00:38

    I'd use SimpleXMLElement.

    ');
    
    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());
    

提交回复
热议问题