Take data from an rss

Asked

Viewed 18 times

0

Very good morning everyone!. Personal I made this script, however, in the new version of PHP it is not working. 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>
';
}
}
?>

1 answer

1


Since you didn’t 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)

Replace "file_get_contents" with "simplexml_load_file", and I’m surprised that this was working before because, the way you do, you’re trying to treat a string as an xml object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.