Get feed titles from any RSS feed with php - php

I'm attempting to build an RSS reader at the moment I'm using php's simplexml using
For example
$xml->item->title
But however this is dependent on the structure of the rss feed itself if the structure is different it won't work so I was wondering if theres a more broader and less specific way to grab all the titles from a RSS feed.
Thanks a lot

There is a RSS Specification document out there. You can find it at http://cyber.law.harvard.edu/rss/rss.html
Therefore, a RSS file always looks the same, but be carefull. There is always something like Atom.
You could use xPATH for searching within the RSS: http://nl.php.net/manual/en/simplexmlelement.xpath.php

maybe it´s an option for you using a contribution like this instead of invent the wheel again: http://www.phpclasses.org/package/3724-PHP-Parse-and-display-items-of-an-RSS-feed.html

You can use some Regex to filter the RSS files and split them into titles, etc. Whatever you want. As you will define which tags to grab data from.
Using something like: $regex = '/<(w+)[^>]*>(.*?)</\1>/s';
preg_match_all($reg_exp, $text, $match);

There are lot of feed formats. Writing code to comply all, is a bit difficult task. so..
I recommend using simple pie. http://simplepie.org/
or you can use google feed api also. here is a example using simple pie.
http://simplepie.org/wiki/setup/sample_page

Related

Parsing XML (Grabbing certain data)

I have a lot of data in an XML file that I need to get out. Currently there is around 1000 pieces of data I need to extract It looks like this
http://pastebin.com/PwfhtbDF
I need to somehow extract just ip="83.42.146.140" out of every one of these. Remember there is around 1000 of these (44000 lines in total). I have tried XML parsing programs but couldn't get it to extract what I want. I was thinking about doing it in PHP somehow.
Any ideas?
Give simpleXML a try. SimpleXML is built into PHP.
This is about it's basic usage (with examples)
$result =~ /\b(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\b/sg);
This is what I ended up using in PHP to grab all the IP's and print them out :). Thanks for all of your help.

How to mix more than 10 RSS feeds?

I just want to mix around 10 rss feeds into one and then i want to filter the results as per my requirements.
I know we can use yahoo pipes like solution for this,but due to some reasons i do not want to use yahoo's facility so is their any open source solution which i can host on my server and mix feeds using it.
I am using PHP for development along with Javascript(jquery).
Can i do this using simplepie.
Yes, use SimplePie. set_feed_url() accepts an array, and will combine all of them for you automatically.
$feed = new SimplePie();
$feed->set_feed_url(array('your','urls','here'));

Get image url from RSS feed description using PHP

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.
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.
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!

How can I search using PHP through an XML file and display the results?

I am trying to build a very simple price comparison script.
Until now, I wrote a code that gets some product xml feeds from shops and with the help of XSLT I create a single-global xml of all those input XMLs. I use the XSLT because the shops have different names for elements.
Now I want to take it one step further and I want to create a search form that will display me the products let's say I have the term "laptop".
I know how to create a form, but I need a coding guidance to understand how to make it to search in my XML file (products.xml) and display let's say the
Thank you
You might want to check out http://php.net/manual/en/class.xmlreader.php
Using that it is pretty easy to navigate through an XML file and grab all the info you need.
EDIT:
On second thought, http://php.net/manual/en/book.simplexml.php is a MUCH simpler way to achieve what you're trying to do. Hence the name, I guess ;)
You can use SimpleXML library to parse your xml file. In my opinion SimpleXML is easier to use than xmlreader. Though SimpleXML is introduced on php5.

Seeking a PHP script to filter an RSS feed

I have about 50 feeds (and growing) that I would like to filter before adding them to Google Reader. Each of the feeds will be filtered for the same keywords. If a keyword match is found, that item will be removed from the feed. Basically I'm just trying to eliminate some noise.
I know I can do this with Yahoo Pipes, but I'm looking for a self-hosted solution.
I'd like to pass a feed to a script on my server. That script will filter out unwanted feed items based on a list of defined keywords. The filtered feed will be the result. I plan to then add the feed to Google Reader.
(BTW, why doesn't Google Reader have filters like Gmail?)
Try using a RSS library like Simplepie. From there, writing the filter logic should be easy-peasy.
Try ReFilter. Looks nice.

Categories