What is the best way to parse XML (RSS) in PHP?
-
I've not coded for about 5 years and I'm trying to get back into things to help out but it's taking some time. I'd like to parse a load of RSS feeds and output to HTML using PHP.
-
Answer:
Use SimpleXML (http://php.net/manual/en/book.simplexml.php), which has been part of Core PHP since PHP 5.0. As a simple example, the following code displays the title nodes of an RSS feed (substitute an actual URL for $rss_url): $feed = simplexml_load_file($rss_url); foreach ($feed->channel->item as $item) { echo $item->title . '<br>'; }
David Powers at Quora Visit the source
Other answers
In addition to the options mentioned, there are several XML parsing extensions available in PHP; I've used DOM. http://php.ca/manual/en/refs.xml.php
Toby Thain
There are different ways of parsing RSS in PHP. I have used the following ways in the past and not had problems with them. SimplePie Last RSS PHP Universal Feed Parser There is also Magpie RSS but it is sometimes unreliable.
Kyle Reddoch
I'd go for SimplePie. I use it in all my projects needing to parse RSS. The data you get is very easy to convert to whatever format you want.
Anders Borg
Related Q & A:
- What is the best way to distribute an audio/video feed from a computer to TVs over existing indoor coax cable?Best solution by Audio-Video Production
- What is the best way to clean LEGO bricks?Best solution by bricks.stackexchange.com
- What is the best way to make UI for an Isometric game in Java?Best solution by Game Development
- What is the best way to calculate a date difference?Best solution by Stack Overflow
- What is the best way to learn PHP?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.