RSS/XML feed parser

Here's some php:

function xml_parser($page,$container,$tags,$number,$cdata) {
  if (!$number) {$number=100;}
  preg_match_all("/<$container>.+<\/$container>/sU",$xml, $items);
   foreach ($items as $item) {
    for($i=0; $i<count($tags); $i++) {
    preg_match("/<$tags[$i](.+)(<\/$tags[$i]>)/sU", $item, $tag);
    $this[$i]=array_map('html_entity_decode', $this[$i]);
     if (count($itemsArray)<$number) {array_push($itemsArray, $this);}
  foreach ($itemsArray as $item) {
  for($i=0; $i<count($tags); $i++) {
  $data[$i]=$item[$i][0];    }
   $dpatterns[0]="/<img(.+)><\/img>/sU"; $dreplacements[0]='<img$1>';
   $dpatterns[1]="/<img(.+)\/>/sU"; $dreplacements[1]='<img$1>';
   $dpatterns[2]="/<(\/|)content?(.+|)>/sU"; $dreplacements[2]='';
   $dpatterns[3]="/border=\"0\"/sU"; $dreplacements[3]='';
   if ($cdata!='hide') {
    $dpatterns[4]="/<\!\[CDATA\[(.+)\]\]>/sU"; $dreplacements[4]='$1';
   else {
    $dpatterns[4]="/<\!\[CDATA\[(.+)\]\]>/sU"; $dreplacements[4]='';
   <dt><a href=\"$link\">$title</a></dt>
   <dd class=\"story\">$description</dd>
   <dd>Date: $date</dd>\r";
return $theData;



Here's some HTML with PHP

<?php echo $bbc; ?>
<?php echo $cnn; ?>
<?php echo $flickr; ?>

Here's what we get... (the lastest feeds from the BBC, CNN, and flickr).


French police and officials begin an operation to clear thousands of migrants from the "Jungle" camp in Calais, ahead of its demolition.
Date: Mon, 24 Oct 2016 13:25:20 GMT
Belgium cannot sign a landmark EU trade deal with Canada, Prime Minister Charles Michel says, because of regional objections.
Date: Mon, 24 Oct 2016 13:35:04 GMT
Police treat an attack on two officers, who were seriously injured after a car was deliberately driven at them in Glasgow, as attempted murder.
Date: Mon, 24 Oct 2016 12:44:28 GMT
A man is found guilty of murdering an Oxford book dealer over a £50,000 first edition of the Wind in the Willows.
Date: Mon, 24 Oct 2016 14:00:41 GMT
Former Eggheads star CJ de Mooi will "continue to co-operate with the Dutch authorities" after a failed attempt to extradite him over an alleged killing.
Date: Mon, 24 Oct 2016 13:36:50 GMT
The Christian owners of a Northern Ireland bakery lose an appeal against a ruling that their refusal to make a 'gay cake' was discriminatory.
Date: Mon, 24 Oct 2016 13:42:32 GMT
2016 is likely to be the first year in recorded history in which levels of CO2 in the atmosphere remain above the symbolically important threshold of 400 parts per million.
Date: Mon, 24 Oct 2016 09:04:35 GMT
Kurdish forces taking part in the offensive to retake the Iraqi city of Mosul from Islamic State militants are besieging a key town to the north-east.
Date: Mon, 24 Oct 2016 10:32:24 GMT
Nicola Sturgeon warns Theresa May she is not "bluffing" about a referendum after the devolved governments' leaders meet to discuss Brexit at No 10.
Date: Mon, 24 Oct 2016 13:48:51 GMT
Home webcams that were hijacked to help knock popular websites offline last week are being recalled in the US.
Date: Mon, 24 Oct 2016 11:21:14 GMT


Hillary Clinton is steadily moving her focus beyond Donald Trump, increasingly planning for what she believes will be her transition to the presidency after a final two-week dash through battleground states.
Date: Mon, 24 Oct 2016 14:01:07 GMT
The most dramatic and unpredictable presidential election in decades is suddenly slipping into a strange state of suspended animation.
Date: Mon, 24 Oct 2016 13:56:46 GMT
For CNN's Sara Murray, it was evident early on that Donald Trump was different. He didn't just attack the media, he held grudges with specific reporters.
Date: Sun, 23 Oct 2016 23:59:48 GMT
A Science Channel found hexagon-shaped "air bombs" over the Bermuda Triangle. The report suggests "air bombs" are capable of bringing down planes and ships.
Date: Mon, 24 Oct 2016 01:20:04 GMT
President Barack Obama directed harsh criticism at Rep. Darrell Issa at a fundraiser Sunday in La Jolla, California, claiming the former House Oversight Committee chairman's "primary contribution to the US Congress has been to obstruct and to waste taxpayer dollars on trumped up investigations that have led nowhere."
Date: Mon, 24 Oct 2016 11:52:16 GMT
In what can best be described as a bundle of cuteness, Nicole McDonald held her son Jadon alone for the first time in what she calls "one of the most profound moments of my life."
Date: Mon, 24 Oct 2016 10:45:03 GMT
We're living in the age of the selfie. But is that a good thing?
Date: Mon, 24 Oct 2016 13:21:23 GMT
Five French nationals were killed when a plane fell from the sky and crashed.
Date: Mon, 24 Oct 2016 12:53:52 GMT
Tom Hayden, a peace activist whose radical views helped spur the 1960s anti-Vietnam War movement, has died.
Date: Mon, 24 Oct 2016 13:25:35 GMT
I met Drew Carey one morning at a West Hollywood eatery, Barney's Beanery, where our conversation ultimately drifted to a place far east of Hollywood -- his favorite place, Cleveland, Ohio. I remember this very funny guy saying in all seriousness how once, just once, he would love to see the baseball team he loves most, the Cleveland Indians, win the World Series.
Date: Mon, 24 Oct 2016 11:53:27 GMT



tickspics  posted a photo:


Date: 2016-10-24T14:04:48Z

matthew_barry1 posted a photo:

Date: 2016-10-24T14:04:44Z
hoy Es lunes, empieza Una nueva semana y con Ella Una nueva oportunidad de Ser Feliz y compartir amor. Vivir con proposito

asuenterprise1 posted a photo:

hoy Es lunes, empieza Una nueva semana y con Ella Una nueva oportunidad de Ser Feliz y compartir amor.  Vivir con proposito

Date: 2016-10-24T14:04:49Z

tarohateruma posted a photo:


Date: 2016-10-24T14:04:50Z

M. Jarrett posted a photo:


Date: 2016-10-24T14:04:41Z
Kylie Jenner Snapchat Videos 2016 Kyliesnapz √146

kingsnapchat posted a photo:

Kylie Jenner Snapchat Videos 2016 Kyliesnapz √146

Play Video : Kylie & Kendall Jenner Buy Matching Ferrari Cars | Full Video Presented to you by ░K░i░n░g░ ░S░n░a░p░C░h░a░t░ Channel! Enjoy the video ! Playlist : Like, share or leave a positive comment to support us. I really appreciate your sensitiveness. Do not forget to follow us on social media and subscribe to our channel. Follow Us On Social Media : Facebook : Twitter : Instagram : Google : Google Page : You can subscribe by clicking on to not mis any of our new videos. Thank You!

Date: 2016-10-24T14:04:49Z

zxcxzcxzccxz posted a photo:


Date: 2016-10-24T14:04:49Z
Various 10.16 164

Aljiman posted a photo:

Various  10.16 164

Date: 2016-10-24T14:04:44Z

ZAGG Luzern posted a photo:


Date: 2016-10-24T14:04:45Z
2016/04 ❸-56

beauness1216 posted a photo:

2016/04 ❸-56

Date: 2016-10-24T14:04:46Z


2007-03-02 dumb_dave says :

Sorry, I'm new to this stuff, willing to learn and all that, but I don't get the idea. Copy that snippet of PHP code into a file and call it, say, parser.php. Copy the other snippet of HTML into a file and call it, for lack of inventiveness, parser.html. Right so far? If so, where's the intermediate step? How does this HTML "call" or "include" the PHP in order to function? Or am I missing something so basic that even asking this will earn me the cherished "Idiot of the Day Award"? Thanks.

2007-03-02 BonRouge says :

You can include the php or just have it in one page. The page would have a '.php' extension - not '.html.'
Here's a simple example of this page (with no style or anthing) in one file.
Save it and change the extension to '.php'. If you don't have a server installed on your machine, you'll have to upload it to a remote server to view it.
If you want, you can take the php code out of that page and save it in a different file and include it into the page - that way, you could use it on more than one page if you wanted.

I hope that makes it a bit clearer.

2007-03-02 dumb_dave says :

Thanks for the explanations. Much clearer now and ... yes, it indeed works like a champ. (Maybe I was just too tired? Putting 1 and 1 together and coming up with 11 instead of two?) Best regards and thanks for all the tips elsewhere as well.

2007-03-07 dumb_dave says :

Useful indeed, BonRouge, but how does one display the <description> tagged material that is buried behind things like <![CDATA[ <p> etc.? Is the PHP code easily modified to handle that? And if so, can one apply it selectively? That is, show the fuller "description" material for one site but then reduce the next site entry to "headines" only (i.e., "titles" and "links") and then toggle the next one back to fuller details? Hope this is not a major headache, but it's beyond my ability to work it out at this stage ... and everything tried brought the larger process to a grinding halt. (This isn't a do-my-homework-for-me question. I'm bewildered by the code.) Thanks.

2007-03-07 BonRouge says :

I thought I'd already sorted out the problem of data wrapped in the CDATA stuff. Does the code have a problem? If you could show me where it's not working, I'll try to improve it.
As for choosing whether to show that particular data or not, yes - I think you could do that by adding another variable. You see near the top where there's a preg_replace() to remove the CDATA tags? You could put that in an if statement - if the variable is not present, remove the CDATA tags, if it is, leave them where they are.
Does that make sense?

2007-03-10 BonRouge says :

I think I found the problem and sorted it out. As you can see, it seems to work OK now. Some of the characters in the Lockergnome feed don't show right on this page though. I wonder if it's anything to do with me being in Japan. Do you see strange characters?

2007-05-01 Ice says :

I have been trawling the web for days looking for something like this. Thanks a WHOLE lot man. I was also wondering if you can modify this parser to merge these fields and display, say, only the latest 10 items? wine

2007-11-02 steve says :

thanks sorted out my cdata parasing problem, seems that is not too clear in the docs


Comment form

Please type the word 'life' here:

BB code available :

  • [b]...[/b] : bold
  • [it]...[/it] : italic
  • [q]...[/q] : quote
  • [c]...[/c] : code
  • [url=...]...[/url] : url