RSS/XML feed parser

Here's some php:

PHP
function xml_parser($page,$container,$tags,$number,$cdata) {
  if (!$number) {$number=100;}
  $stories=0;
  $xml=file_get_contents($page);
  preg_match_all("/<$container>.+<\/$container>/sU",$xml, $items);
  $items=$items[0];
  $itemsArray=array();
   foreach ($items as $item) {
    for($i=0; $i<count($tags); $i++) {
    preg_match("/<$tags[$i](.+)(<\/$tags[$i]>)/sU", $item, $tag);
    $this[$i]=preg_replace("/<$tags[$i]>(.+)(<\/$tags[$i]>)/sU",'$1',$tag);
    $this[$i]=array_map('html_entity_decode', $this[$i]);
    }
     if (count($itemsArray)<$number) {array_push($itemsArray, $this);}
   }
  $theData="<dl>";
  foreach ($itemsArray as $item) {
  for($i=0; $i<count($tags); $i++) {
  $data[$i]=$item[$i][0];    }
   $title=$data[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]='';
   }
   $description=preg_replace($dpatterns,$dreplacements,$data[1]);
   $link=preg_replace("/<link.+href=\"(.+)\"(.+|)\/>/sU",'$1',$data[2]);
   $date=$data[3];
   $theData.="
   <dt><a href=\"$link\">$title</a></dt>
   <dd class=\"story\">$description</dd>
   <dd>Date: $date</dd>\r";
  }
$theData.="</dl>";
return $theData;
}

$container='item';
$tags=array('title','description','link','pubDate');
$bbc=xml_parser("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml",$container,$tags,10,'');
$cnn=xml_parser("http://rss.cnn.com/rss/cnn_topstories.rss",$container,$tags,10,'');

$container='entry';
$tags=array('title','content','link','published');
$flickr=xml_parser("http://api.flickr.com/services/feeds/photos_public.gne",$container,$tags,10,'');

Here's some HTML with PHP

HTML/PHP
<h2>bbc</h2>
<?php echo $bbc; ?>
<h2>cnn</h2>
<?php echo $cnn; ?>
<h2>flickr</h2>
<?php echo $flickr; ?>

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

bbc

A child with underlying health conditions is among 708 people whose deaths were reported in the past day.
Date: Sat, 04 Apr 2020 17:15:54 GMT
The 57-year old MP wins a decisive victory over two rivals and vows to lead party "into new era".
Date: Sat, 04 Apr 2020 12:37:38 GMT
People across the UK appear to be adhering to social distancing rules, minister Michael Gove has said.
Date: Sat, 04 Apr 2020 16:44:17 GMT
Prime Minister Pedro Sánchez has extended lockdown measures in the country until 25 April.
Date: Sat, 04 Apr 2020 14:43:51 GMT
Staff at the Glasgow home said they were "closely monitoring" the health of other people in their care.
Date: Sat, 04 Apr 2020 15:35:21 GMT
Nursing chiefs raise fears about protective equipment following the deaths of two nurses.
Date: Sat, 04 Apr 2020 15:56:22 GMT
Watford General Hospital is closed to all patients except women expecting to give birth.
Date: Sat, 04 Apr 2020 15:54:09 GMT
A day of remembrance is held to honour those who have died in the coronavirus outbreak.
Date: Sat, 04 Apr 2020 08:15:41 GMT
The government has pledged to increase daily testing tenfold by the end of the month.
Date: Sat, 04 Apr 2020 08:03:58 GMT
A man is in custody after shoppers were attacked in the south-eastern town of Romans-sur-Isère.
Date: Sat, 04 Apr 2020 13:59:16 GMT

cnn

In photos | Newsletter | Podcast | Q&A | CNN town hall
Date:
Date: Sat, 04 Apr 2020 12:20:49 GMT
Tracking Covid-19 cases in the US
Date:
Newsletter | Podcast | Q&A | CNN town hall • Tracking the virus: Coronavirus cases in the US by state • Live Updates: Coronavirus deaths pass 59,000 globally
Date: Sat, 04 Apr 2020 01:16:59 GMT
The US has surpassed 7,000 deaths and some state leaders say there's still a lot they're missing in the battle against the coronavirus.
Date: Sat, 04 Apr 2020 17:27:24 GMT
Date: Sat, 04 Apr 2020 15:20:51 GMT
• When coronavirus hit her city, this mayor didn't wait for her governor to sound the alarm
Date: Sat, 04 Apr 2020 15:57:26 GMT
Tampa Mayor Jane Castor is used to dealing with disasters like hurricanes that cripple her Florida city. But none have ever come close to the magnitude of destruction she is bracing for with the novel coronavirus pandemic.
Date: Sat, 04 Apr 2020 14:46:44 GMT
More than a week after President Donald Trump said he would authorize the use of a wartime-era law to force General Motors to produce ventilators, the company still hasn't received a formal order from the federal government. GM, as a result, hasn't allowed private companies or hospitals to place orders, according to a source familiar with the matter.
Date: Fri, 03 Apr 2020 22:41:05 GMT
CNN's Jim Acosta asks President Donald Trump who in his administration dropped the ball on preparing for a possible pandemic, citing the lack of masks and other medical equipment.
Date: Fri, 03 Apr 2020 22:41:06 GMT

flickr

20200313_191605

orbit9000 posted a photo:

20200313_191605

Date: 2020-04-04T17:36:27Z
Pasir Ris Park, Singapore

cattan2011 posted a photo:

Pasir Ris Park, Singapore

Date: 2020-04-04T17:36:31Z
Untitled

talitha69 posted a photo:

Untitled

Visit this location at Virtual Chelsea Hotel Plaza Galleries in Second Life

Date: 2020-04-04T17:36:38Z

chhillglass posted a photo:

Date: 2020-04-04T17:36:42Z

n1968m posted a photo:

Date: 2020-04-04T17:36:43Z
2020-04-04_01-36-42

warrenseeley posted a photo:

2020-04-04_01-36-42

Date: 2020-04-04T17:36:48Z
2020-04-04_07-36-40

jørn skov hansen posted a photo:

2020-04-04_07-36-40

cof

Date: 2020-04-04T17:36:49Z
...

Tina Nirschl-Löhr posted a photo:

...

Date: 2020-04-04T17:36:28Z
No Pictures Please

Bria Ka'oir posted a photo:

No Pictures Please

{"subsource":"done_button","uid":"330F30E9-EBB1-432D-A251-296380940E02_1586020148729","source":"other","origin":"gallery","source_sid":"330F30E9-EBB1-432D-A251-296380940E02_1586020148738"}

Date: 2020-04-04T17:36:31Z
Wiesbaden Lost Places Hospital

>kaboom< posted a photo:

Wiesbaden Lost Places Hospital

Date: 2020-04-04T17:36:41Z

Comments

#1
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.

#2
2007-03-02 BonRouge says :

dave,
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.

#3
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.

#4
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.

#5
2007-03-07 BonRouge says :

dave,
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?

#6
2007-03-10 BonRouge says :

dave,
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?

#7
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

#8
2007-11-02 steve says :

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

s

#9
2019-04-28 Suezef says :

sildenafil without a prescription

#10
2019-04-28 Evazef says :

tadalafil

#11
2019-04-28 Terrellimary says :

? - . - , , ! - ! <b> </b>, 80% . , <b> </b>. , . . - <b> </b>. <b></b> <b> </b> <b></b>. <b> - </b> . <b></b> <b></b> <b> </b> <b> 1 </b>. ! ! -! <b> </b> --> http://c.trktp.ru/ud6b

#12
2019-04-28 SylviaTaimb says :



-----------------------------------
, , . - . interchange ( ) - , , , . - , . , . , . , , , . 0,75%-3%. . ?


, :

<a href="https://mastertarget.ru/scripts/click.php?a_aid=esif22&amp;a_bid=39b43ce0" target="_blank"><strong> </strong><br/></a><img style="border:0" src="https://mastertarget.ru/scripts/imp.php?a_aid=esif22&amp;a_bid=39b43ce0" width="1" height="1" alt="" />

#13
2019-04-28 Terrellimary says :

? - . - , , ! - ! <b> </b>, 80% . , <b> </b>. , . . - <b> </b>. <b></b> <b> </b> <b></b>. <b> - </b> . <b></b> <b></b> <b> </b> <b> 1 </b>. ! ! -! <b> </b> --> http://c.trktp.ru/ud6b

#14
2019-05-27 Evazef says :

cafergot online

#15
2019-05-27 Janezef says :

advair prescription

#16
2019-05-27 Write Essay For Me says :

homework help

#17 #18
2019-05-27 cheap insurance auto says :

car insurance quote compare car insurance rates

#19
2019-05-27 Kimzef says :

phenergan 25 mg

#20
2019-05-27 RogovaEvridika1989Sig says :

fdf7 forum be is online


http://ph-90e13-3-1.com/

comprare is 5mg

#21
2019-05-27 Evazef says :

acytoclovir 800

#22
2019-05-27 Kiazef says :

sildenafil citrate over the counter

#23
2019-05-27 tjgjInill says :

virgin online casino free casino slot games vegas slots online <a href="http://redcasinoonline.com/">online - games</a>

#24
2019-05-27 Evazef says :

dapoxetine buy

#25
2019-05-28 losElome says :

slotomania on facebook slotomania free online slots game <a href="http://playersonlinecasinogo.com/">hollywood casino dit is spam slots online</a>

#26
2019-05-28 car insurance quotes says :

cheap car insurance online

#27
2019-05-28 aarp insurance auto says :

automobile insurance auto insurance quotes

#28
2019-05-28 Evazef says :

furosemide 40 mg

#29
2019-05-28 Annazef says :

tadalafil levitra 10 mg price

#30
2019-05-28 Kimzef says :

cafergot buy

#31
2019-05-28 Evazef says :

vardenafil 20mg tab

#32
2019-05-28 Kimzef says :

allopurinol 300 mg

#33
2019-05-28 Erotic Chat says :

cam girls web cam girls

#34
2019-05-28 Evazef says :

amoxicillin price

#35
2019-05-28 Janezef says :

vardenafil

#36
2019-05-28 Good Homework Music says :

boston college application essay custom writing

#37
2019-05-28 jhvReart says :

zone online casino games casino blackjack <a href="http://mylistonlinecasino.com/">winstar world casino</a>

#38
2019-05-28 Janezef says :

tadalafil generic

#39
2019-11-27 amibcobixc says :

#40
2019-11-27 xtgbbghnwy says :

#41
2019-11-27 iuajxcuvky says :

#42
2019-11-27 icdvlpofwm says :

#43
2019-11-27 wmledhrcen says :

<a href="http://genericlevitr.com/">generic levitra overnight delivery</a>

#44
2019-11-27 uygtbzhwut says :

#45
2019-11-27 qeodhabmlf says :

<a href="http://genericlevitr.com/">generic levitra overnight delivery</a>

#46
2019-11-27 ddmobpnspe says :

#47
2019-11-27 gliydpwwph says :

#48
2019-11-27 ezrrqmxauc says :

#49
2019-11-27 udfsqczvwp says :

#50
2019-11-27 hdljdehziu says :

#51
2019-11-27 MichaelSpini says :

http://www.paroxetine.team

#52
2019-11-27 sfssdexces says :

#53
2019-11-27 djqahoxvym says :

#54
2019-11-27 Kennethdaply says :

www.ventolin.us.com
generic atenolol

#55
2019-11-27 zyxhhytzsl says :

<a href="http://genericlevitr.com/">what is generic levitra</a>

#56
2019-11-27 chfyeqweli says :

#57
2019-11-27 lsseiiwaln says :

#58
2019-11-27 bbrtuhwgmj says :

#59
2019-11-27 gnfgtiocsz says :

#60
2019-11-27 kaqgntlnxb says :

#61
2019-11-27 wkzbcmirvk says :

#62
2019-11-27 sqaomydwnu says :

#63
2019-11-27 wpaqamzwnf says :

#64
2019-11-27 npqgpovhno says :

#65
2019-11-27 gcofvwowzu says :

<a href="http://genericlevitr.com/">generic levitra prices</a>

#66
2019-11-27 tnecjddrxe says :

<a href="http://genericlevitr.com/">adc levitra generic</a>

#67
2019-11-27 qnxxlrehxo says :

#68
2019-11-27 iiwvitelbc says :

#69
2019-11-27 hzobzroilm says :

#70
2019-11-27 ndpqofrxwk says :

#71
2019-11-27 MichaelSpini says :

http://zofran.us.com

#72
2019-11-27 kgdhurnnfz says :

#73
2019-11-27 ebqcqjdzdn says :

#74
2019-11-27 ffchomfrdu says :

#75
2019-11-28 bjyiqnrkiz says :

#76
2019-11-28 rijzeuitrt says :

#77
2019-11-28 Kennethdaply says :

www.buyprednisone.us.com
cheap methotrexate

#78
2019-11-28 lsshdhkvlm says :

<a href="http://genericlevitr.com/">buy cheap generic levitra</a>

#79
2019-11-28 vxtshfcjej says :

#80
2019-11-28 nfkwexgdiy says :

#81
2019-11-28 hxyqntwghr says :

#82
2019-11-28 pgozhesbbc says :

#83
2019-11-28 sxpyuwexbu says :

#84
2019-11-28 nfetnqpgrq says :

<a href="http://genericlevitr.com/">levitra generic pics</a>

#85
2019-11-28 mytlitgbhv says :

#86
2019-11-28 zcryadkncs says :

#87
2019-11-28 kdrgiqnnwr says :

<a href="http://genericlevitr.com/">generic levitra us</a>

#88
2019-11-28 eylqzwmatg says :

#89
2019-11-28 gsqxzqphwl says :

#90
2019-11-28 abqptczkjw says :

#91
2019-11-28 MichaelSpini says :

www.biaxin.company

#92
2019-11-28 gcqhabzupy says :

#93
2019-11-28 zfcolztesn says :

#94
2019-11-28 yzcestvncc says :

#95
2019-11-28 MichaelSpini says :

cheap trazodone
cheap stromectol

#96
2019-11-28 pupyidjxvo says :

#97
2019-11-28 pgtmsjsnvs says :

<a href="http://genericlevitr.com/">cheapest generic levitra online</a>

#98
2019-11-28 crhlqntouu says :

#99
2019-11-28 fdcdlhktgp says :

#100
2019-11-28 fecyudcqjn says :

#101
2019-11-28 asdmhiwxki says :

#102
2019-11-28 fpmtdiszlx says :

#103
2019-11-28 pbkfgjhcjt says :

#104
2019-11-28 avjlhbauid says :

#105
2019-11-28 bhjzsdedlj says :

#106
2019-11-28 jsvxfzifaw says :

#107
2019-11-28 cinrsikdvx says :

#108
2019-11-28 gdrkpoqbdk says :

#109
2019-11-28 vfrsqrmdva says :

#110
2019-12-27 MichaelSpini says :

lexapro generic cheap xenical

#111
2019-12-27 tgnpwwtwwr says :

Gabby dissection reach that the РІ 10 <a href="http://sildenafiltotake.com/">sildenafil 20mg</a>

#112
2019-12-27 MichaelSpini says :

cheap tadalafil valtrex

#113
2019-12-27 mjjouactpz says :

Twenty of zoonosis you bought a <a href="http://aaedpills.com/">ed meds pills drugs</a>

#114
2019-12-28 dmttbhpptt says :

and the Provocative-type PokР“mon coupled Sequencing Pipes Authenticity has a vagal to sixty on intraocular <a href="http://levitrars.com/">erectile medicines levitra</a>

#115
2019-12-28 Stewartmooma says :

buy tadalafil uk

#116
2019-12-28 ylxxsifkwm says :

Chuckles is most when a author of sly come to an end <a href="http://sildenafilfas.com/">sildenafil online</a>

#117
2019-12-28 dnugklwyaw says :

I opposite these this prepackaged (as a replacement for the most portion)

#118
2020-01-27 Janezef says :

prednisone 40 mg tablet

#119
2020-01-27 Kiazef says :

buy generic valtrex online cheap

#120
2020-01-28 dvgtThync says :

Danazol Yasmin Exelon <a href="http://diclofenacvoltarenax.com/#">Dostinex</a> Clomid

#121
2020-01-28 vdbrEmpow says :

cash till payday loan cash till payday loan direct payday loan lenders <a href="http://paydayloanjyd.com/#">a payday loan</a> payday loan no fax

#122
2020-02-27 Wimzef says :

hydrochlorothiazide 25

#123 #124
2020-02-27 Teozef says :

buy phenergan 10mg online

#125
2020-02-28 Wimzef says :

propranolol 10 mg tablet

#126
2020-02-28 Kimzef says :

diflucan 150 mg tablets

#127
2020-02-28 Kiazef says :

indocin for sale

#128
2020-02-28 egkscluch says :

short term loans cash today short term loans instant cash short term advance loan dwp <a href="http://shorttermloanshek.com/#">short term cash advance lenders</a> short term cash loan gold coast

#129
2020-02-28 Kiazef says :

amoxicillin 5

#130
2020-03-27 Kimzef says :

buy aralen online uk

#131
2020-03-27 Annazef says :

generic plaquenil coupon zithromax

#132
2020-03-27 Teozef says :

resochina

#133
2020-03-27 Evazef says :

plaquenil online

#134
2020-03-27 Teozef says :

aralen tablets

#135
2020-03-27 Evazef says :

buy aralen tablet

#136
2020-03-27 Evazef says :

zithromax pills for sale

#137
2020-03-27 Evazef says :

azithromycin 250mg tablets

#138
2020-03-27 Janezef says :

azithromycin brand name india

#139
2020-03-27 Janezef says :

zithromax azithromycin

#140
2020-03-27 Teozef says :

azithromycin 250 mg

#141
2020-03-27 bfhmDooro says :

levitra cost per pill levitra 10 mg cheap levitra <a href="https://levitrakgsy.com/#">levitra com</a> levitra medication

#142
2020-03-28 Janezef says :

azithromycin 500

#143
2020-03-28 Teozef says :

chloroquine prescription

#144
2020-03-28 Evazef says :

order azithromycin

#145
2020-03-28 Teozef says :

chloroquine generic name

#146
2020-03-28 Annazef says :

buy hydroxychloroquine buy cleocin

#147
2020-03-28 Teozef says :

furosemide 40 mg tablet

#148
2020-03-28 Janezef says :

chloroquine phosphate generic name

#149
2020-03-28 Janezef says :

where to get azithromycin over the counter

Comment form

Please type the word 'whisky' here:

BB code available :

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