Answer the question
In order to leave comments, you need to log in
How to limit access to RSS file?
There is a primitive PHP code that accesses the RSS file and takes the titles and links from there. It is necessary to make sure that the number of hits is limited (for example, to display 10 links). I know that counters are needed, but I don’t know where to implement them. Complete noob at PHP. It’s a shame to contact Freelancing with such a trifle.
I am attaching the code.
<?
$url = 'http://antonkurilov.ru/russian.xml';
$rss = simplexml_load_file($url);
foreach ($rss->channel->item as $item) {
echo '<a href="'.$item->guid.'" target="_blank">'.$item->title.'</a>';
}
?>
Answer the question
In order to leave comments, you need to log in
break - stops the execution of the cycle, therefore we consider the cycle when the required threshold is reached break;
$url = 'http://antonkurilov.ru/russian.xml';
$rss = simplexml_load_file($url);
$i = 1;
foreach ($rss->channel->item as $item) {
echo '<a href="'.$item->guid.'" target="_blank">'.$item->title.'</a>';
if (++$i > 10) break;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question