S
S
sergeyviktorovich2020-01-03 01:23:49
PHP
sergeyviktorovich, 2020-01-03 01:23:49

How to make a script that, when run from the command line, will display the latest 5 news items?

The news site Lenta.ru provides a list of news in rss format at https://lenta.ru/rss . It is necessary to create a getLastNews.php script, which, when run from the command line, will display the last 5 news in the format
from the Bitrix command line, you need to run the script, and the script must be done according to the rules of Bitrix, how to get data from xml on Bitrix, are there any built-in features?
Title
Link to the news
Announcement

I tried something, but I don’t know how to do it right

$user_id = 'self';
$instagram_cnct = curl_init(); // инициализация cURL подключения
curl_setopt($instagram_cnct, CURLOPT_URL, "https://lenta.ru/rss"); // подключаемся
curl_setopt($instagram_cnct, CURLOPT_RETURNTRANSFER, 1); // просим вернуть результат
curl_setopt($instagram_cnct, CURLOPT_TIMEOUT, 15);
$media = json_decode(curl_exec($instagram_cnct)); // получаем и декодируем данные из JSON
curl_close($instagram_cnct); // закрываем соединение
$limit = 5;

<? foreach (array_slice($media->data, 0, $limit) as $data) {
                echo '<a href="' . $data->permalink . '" target="_blank">';
             
                echo '</a>';
            } ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2021-01-04
@anton99zel

do it according to Bitrix rules

And what are the rules?
Is n't it easier to install rss from the market if you can't parse it yourself on php?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question