I want after reading the html page with file_get_contents
and selecting what matters with preg_match_all
to be automatically generated xml (calling the function below) and generating the file.
As there are several lists to be generated in the same php, I did not want to have to repeat the commands of XmlWriter
, just call the function to do automatically.
<?php
header ('Content-Type:application/xml');
$html = file_get_contents('http://www.teste.com/');
$re = '/href=\'(.*?)\'>(.*?)</(.*?)';
preg_match_all($re, $html, $key);
foreach($key[1] as $i)
function lista_xml($xml){
$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument('1.0','UTF-8');
$xml->startElement('items');
$xml->startElement('lista');
$xml->writeCData('$nome');
$xml->endElement();
$xml->startElement('canal');
$xml->startElement('titulo');
$xml->writeCData('.$key[2][$i].');
$xml->endElement();
$xml->startElement('img');
$xml->writeCData();
$xml->endElement();
$xml->startElement('link');
$xml->writeCData('.$key[1][$i].');
$xml->endElement();
$xml->startElement('detalhes');
$xml->writeCData('<center><img src='".$key[3][$i]."'/> '.$key[2][$i].'</center>');
$xml->endElement();
$xml->endDocument();
echo $xml ->outputMemory();
$xml->flush();
unset($xml);
}
?>