123 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of 123.php

  1. php
  2. <?php
  3.  
  4. // Создаем функцию для получения данных из RSS
  5.  
  6. function getRssData($url) {
  7.     // Инициализируем CURL и устанавливаем настройки
  8.     $ch = curl_init();
  9.     curl_setopt($ch, CURLOPT_URL, $url); // Устанавливаем URL для запроса
  10.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Включаем возврат результата запроса в виде строки
  11.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // Ограничиваем время соединения
  12.     curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Ограничиваем время выполнения запроса
  13.  
  14.     // Отправляем запрос и получаем результат
  15.     $data = curl_exec($ch);
  16.  
  17.     // Закрываем CURL
  18.     curl_close($ch);
  19.  
  20.     // Возвращаем полученные данные
  21.     return $data;
  22. }
  23.  
  24. // Задаем URL RSS-ленты
  25. $rssUrl = "https://www.tks.ru/logistics.rss";
  26.  
  27. // Получаем данные из RSS-ленты
  28. $rssData = getRssData($rssUrl);
  29.  
  30. // Парсим полученные данные из RSS в формате XML
  31. $parsedData = simplexml_load_string($rssData);
  32.  
  33. // Перебираем полученные новости и выводим информацию
  34. foreach ($parsedData->channel->item as $item) {
  35.     echo "<h2>" . $item->title . "</h2>"; // Выводим заголовок новости
  36.     echo "<p>" . $item->description . "</p>"; // Выводим описание новости
  37.     echo "<a href='" . $item->link . "'>Подробнее</a>"; // Выводим ссылку на подробности
  38.     echo "<hr>"; // Делаем разделитель между новостями
  39. }
  40.  
  41. ?>
File Description
  • 123
  • PHP Code
  • 19 Feb-2024
  • 1.76 Kb
You can Share it: