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

1k Views Asked by At

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.

1

There are 1 best solutions below

0
user3865616 On

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'];
}