G
G
grechnik2282019-11-01 17:40:26
PHP
grechnik228, 2019-11-01 17:40:26

php. How to display all item_news from rss feed?

There is a format feed.

<item>
      <title>title sdfs </title>
      <description>description text</description>
      <link>site.com/1</link>
      <item_news>
        <item_news_title>text 1</item_news_title>
        <item_news_description>description text 1</item_news_description>
        <item_news_url>google.ru</item_news_url>
      </item_news>
      <item_news>
        <item_news_title>text 2</item_news_title>
        <item_news_description>description text 2</item_news_description>
        <item_news_url>google.com</item_news_url>
      </item_news>
    </item>
    <item>
      <title>title sdfsdd </title>
      <description>description text 2</description>
      <link>site.ru/2</link>
      <item_news>
        <item_news_title>text 3</item_news_title>
        <item_news_description>description text 3</item_news_description>
        <item_news_url>google.de</item_news_url>
      </item_news>
      <item_news>
        <item_news_title>text 4</item_news_title>
        <item_news_description>description text 4</item_news_description>
        <item_news_url>google.fr</item_news_url>
      </item_news>
    </item>

There is a lot of news, I pull out only the first five items
$i = 0;
foreach ($xml->channel->item as $item) {

  if($i<5){
  
  echo "<h3>". $item->title . "</h3>";
    echo $item->link."<br/>";
    echo $item->description."<br/>";
    echo $item->item_news->item_news_title."<br/>";
  }
 $i++;
}

But how to display all the item_news that are?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2019-11-01
@grechnik228

echo "<h3>". $item->title . "</h3>";
echo $item->link."<br/>";
echo $item->description."<br/>";
foreach($item->item_news as $news) {
  print_r($news);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question