1

I want to get the url of an image (where it's stored) from the description of a RSS feed, so then I can put that url inside a variable.

I know that for getting the link of the RSS feed post I have to use $feed->channel->item->link; where $feed is $feed=simplexml_load_file("link_of_the_feed";.

But what if I have get the image url of the post, do I have to use something like $feed->channel->item->image;?

I really don't know, maybe a RSS parser like MagPie RSS which I tried without results? Thanks in advance.

2 Answers2

1

If the image node is at the top level of the item node, then yes. If it's deeper than the item node, you'll have to traverse it accordingly. It would be helpful if you posted your XML.

EDIT: you can also check out my answer here on how to parse through an XML file with PHP.

Community
  • 1
  • 1
John
  • 3,296
  • 2
  • 24
  • 36
1

You're on the right track! But it all depends on the format that the RSS Feed is set up in.

The item node actually contains a whole bunch of different fields, of which link is only one. Take a look here for information on the other fields that the item node contains.

Now, if the RSS feed points directly to the image file, then you can just use item->link. More likely, however, the link points to a blog post or something that has the image embedded in it. In this case, you can undertake some processing on $feed->channel->item->description to find what you need. The description node contains an escaped HTML summary of the post, and then from there, you can just use a regular expression to find the source of the image. Also remember: before you start using the regular expressions, you might need to decode the description using htmlspecialchars_decode() before you start processing it with the regular expressions - in my own experience, descriptions often come formatted with special characters escaped.

I know that's a lot of information, but once you get started it's really not as hard as it sounds. Good luck!

Fabian Tamp
  • 4,416
  • 2
  • 26
  • 42
  • So I must break into pieces the description and find with regular expressions only the part where appears, right? –  Dec 29 '11 at 00:27
  • Yep, spot on :) and then from there, you're looking for the `src` attribute of the image. – Fabian Tamp Dec 29 '11 at 04:55