How to generate and deliver an XML file via PHP page

0

How do I execute a PHP script by URL, which returns an XML file, for example:

  

link

The code:

<?php
function GerarXml($nome, $re, $html)
{header ('Content-Type:application/xml');
preg_match_all($re, $html, $data);
    //Inicia o XML
    $xml = new XMLWriter();
    $xml->openMemory();
    $xml->startDocument('1.0','UTF-8');
    $xml->startElement('items');

    foreach ($data[1] as $key => $value) {

        $xml->startElement('playlist_name');
        $xml->writeCData($nome);
        $xml->endElement();

        $xml->startElement('channel');

        $xml->startElement('title');
        $xml->writeCData($data[2][$key]);
        $xml->endElement();

        $xml->startElement('playlist_url');
        $xml->writeCData($data[1][$key]);
        $xml->endElement();

        $xml->startElement('logo_30x30');
        $xml->writeCData('<center><img src="'.$data[3][$key].'"/> '.$data[2][$key].'</center>');
        $xml->endElement();

        $xml->endElement(); //Finaliza canal
    }

    //Finaliza o </items>
    $xml->endElement();

    $xml->endDocument();
    echo $xml->outputMemory();
    $xml->flush();
}
?>
    
asked by anonymous 05.11.2018 / 00:57

0 answers