Good community, I have a doubt, I have created an xml view from a file with extension .php, but I would like to know if, Can I replicate what I have done but from an .xml file ?. Thank you very much in advance.
<?php
$html = "";
$url = "https://sports.yahoo.com/soccer/mls/rss.xml?shangrila=1";
$xml = simplexml_load_file($url);
header("content-type: text/xml");
echo('<?xml version="1.0" encoding="UTF-8" ?>');
// $html .= ' <rss version="2.0">'; // si descomentas se verá como un rss
$html .= ' <channel>';
foreach ($xml->channel as $object) {
$html .=' <title> '.$object->title.' </title>'; // cabecera
$html .=' <description> '.$object->description.' </description>';
}
for($i=0; $i<10;$i++){ // cantidad de noticias
$title = $object->item[$i]->title;
$link = $object->item[$i]->link;
$description = $object->item[$i]->description;
$pubDate = $object->item[$i]->pubDate;
$guid = $object->item[$i]->guid;
$html .='<item>';
$html .=' <title> '.$title.' </title>';
$html .=' <link> '.$link.' </link>';
$html .=' <description>'.$description.' </description>';
$html .=' <pubDate> '.$pubDate.' </pubDate>';
$html .=' <guid> '.$guid.' </guid>';
$html.='</item>';
}
$html .= " </channel>";
// $html .= " </rss>";
//
echo $html;
file_put_contents("rss.xml",$html);
?>
PS: if you want to see the code that I created, let me know and I'll post it.