Javascript-форум (https://javascript.ru/forum/)
-   Серверные языки и технологии (https://javascript.ru/forum/server/)
-   -   Парсер из RSS на Php или есть другие варианты? (https://javascript.ru/forum/server/74266-parser-iz-rss-na-php-ili-est-drugie-varianty.html)

spinastr 25.06.2018 23:33

Парсер из RSS на Php или есть другие варианты?
 
Есть мастера PHP ? (Парсер RSS)

Помогите:
1.Вывести картинку у новостей (у меня получилось вывести простую ссылку)
2.Заголовок сделать ссылкой на оригинальную новость на сайте.
3.Дату на Русском (Вывел но она на Английском языке)

демо: страница http://h116641.s08.test-hf.su/rss/rss.php

Вот рабочий код (Может в нём полно ошибок, но не много) - знаний не хватает.

<?php
header('Content-Type: text/html; charset=UTF-8');

$path = 'https://62.xn--b1aew.xn--p1ai/news/rss';;
$ctx = stream_context_create(array('http' => array('timeout' => 6)));
$file = file_get_contents($path, 0, $ctx);
if ($file) {
$rss = simplexml_load_string($file);



foreach ($rss->channel->image as $image){
$image = $image->url;
echo "$image";



}


foreach ($rss->channel->item as $item){
$namespaces = $item->getNameSpaces(true);
$yandex = $item->children($namespaces['yandex']);
$full_text = (string)$yandex->{'full-text'};
$full_text = mb_substr(strip_tags($full_text), 0, 9250, 'UTF-8');
$title = $item->title;
$pubDate = $item->pubDate;
$pubDate = date("D, d M Y H:i:s T", strtotime($pubDate));
echo "<div style='margin-bottom: 20px;font-weight: bold;'>{$title}</div>";
echo "<div style='margin-bottom: 20px;'>{$pubDate}</div>";
echo "<div style='margin-bottom: 20px;'>{$full_text}</div>";


if (isset($item->enclosure)) {
echo $item->enclosure["url"].'<br>';


}



}


}

?>


Часовой пояс GMT +3, время: 16:22.