Get data from an rss

0

Good morning everyone !. Personally I did this script, however, in the new version of PHP it is not working. Do you know how I can make this code in the new version?

<?php
// Mostrar Data na Tela.
$titulo = array();
$data = array();
$link = array();
$quantos = 0;
$exibir = 12;
$limite_title = 100;

foreach(file_get_contents("https://www.clubhost.com.br/cliente/announcementsrss.php")->channel->item as $item)
{
$titulo[] = utf8_decode(substr($item->title, 0, $limite_title)."...");
$link[] = $item->link;
$data[] = utf8_decode($item->pubDate);
$quantos++;
}

for($i = $quantos-($exibir+1); $i < $quantos-1; $i++)
{
if($titulo[$i]!="")
{
echo
'
<li>
<a href="'.$link[$i].'" target="_blank" title="Leia mais clicando aqui!">'.utf8_encode($titulo[$i]).'
</li>
';
}
}
?>
    
asked by anonymous 18.07.2017 / 16:41

1 answer

1

Since you did not report the error, I can only guess from the code that the problem is on the line:

foreach(file_get_contents("https://www.clubhost.com.br/cliente/announcementsrss.php")->channel->item as $item)

Change "file_get_contents" to "simplexml_load_file", and I'm surprised that this was working earlier because, in the way you do, you're trying to treat a string as an xml object.     

18.07.2017 / 19:28