user3865616
user3865616

Reputation: 61

How to get the url from <media:content> in a RSS feed using SimplePie

I'm trying to use SimplePie and PHP to grab the url value from the tag. An example of the RSS code is:

<item>
  <title>Headline goes here</title>
  <link>https://sampledomain.com/index.html</link>
  <description><![CDATA[ Body copy is here. ]]></description>
  <dc:creator>Migraine Team</dc:creator>
  <pubDate>Mon, 29 Jul 2019 16:00:01 +0000</pubDate>
  <media:content url="https://sampledomain.net/imagetograb.jpg" medium="image"/>
  <guid>https://sampledomain.com/index.html</guid>
</item>

I loop through the items…

foreach ($feed->get_items() as $item) {

}

but I'm uncertain how to grab the url value from the tag.

Upvotes: 2

Views: 1134

Answers (1)

user3865616
user3865616

Reputation: 61

This is what eventually worked for me:

foreach ($feed->get_items() as $item) {
  $item->get_item_tags('http://search.yahoo.com/mrss/','content')[0]['attribs']['']['url'];
}

Upvotes: 4

Related Questions