How can I parse a complex XML with PHP and CDATA?

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

Was this solution helpful to you?

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

Just Added Q & A:

Find solution

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.