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

Ayatollah Khamenei praises the Revolutionary Guard amid anger over the downing of a passenger jet.
Date: Fri, 17 Jan 2020 17:08:26 GMT
Former special prosecutors from Bill Clinton's impeachment trial are on the president's team.
Date: Fri, 17 Jan 2020 17:28:57 GMT
The virus emerged in December, two people have died and it has been detected in three countries.
Date: Fri, 17 Jan 2020 21:50:27 GMT
Boris Johnson will also address the nation and cabinet will be held outside London on 31 January.
Date: Fri, 17 Jan 2020 22:33:17 GMT
The study by Which? compared the price of 53 products but did not include discounters Aldi and Lidl.
Date: Sat, 18 Jan 2020 00:02:21 GMT
There was outrage after the restaurant of the late French chef Paul Bocuse lost one of its stars.
Date: Fri, 17 Jan 2020 22:46:00 GMT
The Labour MP sets out her pitch for Labour leadership, promising a "shake up" of government if elected.
Date: Fri, 17 Jan 2020 20:49:16 GMT
A judge rules Guardian columnist Owen Jones was targeted due to his sexuality and political views.
Date: Fri, 17 Jan 2020 19:52:56 GMT
While the nation has its eyes turned to Iowa, voters in Minnesota have already cast the first ballots.
Date: Fri, 17 Jan 2020 23:42:03 GMT
After two weeks, lawyers finally choose the 12 jurors for the trial from about 700 candidates.
Date: Fri, 17 Jan 2020 20:36:27 GMT

cnn

Date:
House Democrats on Friday released new documents from indicted Rudy Giuliani associate Lev Parnas ahead of the Senate trial that includes new information about the apparent surveillance of former US Ambassador Marie Yovanovitch.
Date: Sat, 18 Jan 2020 00:07:43 GMT
Fox News host Laura Ingraham asks Sen. Martha McSally (R-AZ) about wanting witnesses in the Senate impeachment trial.
Date: Fri, 17 Jan 2020 23:38:29 GMT
Senate leaders are preparing for a contentious session Tuesday that could stretch several hours as well as send the chamber into a closed session as Democrats try to force the GOP into accepting witness testimony and documents to be produced during the impeachment trial, according to multiple senators and other sources familiar with the planning.
Date: Fri, 17 Jan 2020 22:57:47 GMT
After President Trump said that he didn't know Rudy Giuliani associate Lev Parnas, Parnas' attorney Joseph Bondy released a video that shows the two together in a group of people at Mar-a-Lago.
Date: Fri, 17 Jan 2020 00:08:44 GMT
The announcement that former independent counsel Ken Starr is joining President Donald Trump's impeachment defense team surprised many on Friday, but one person, apparently, had an especially notable reaction to the news.
Date: Fri, 17 Jan 2020 17:45:41 GMT
Before he was President, Donald Trump offered his opinion on Kenneth Starr, the prosecutor whose work led to President Bill Clinton's impeachment.
Date: Fri, 17 Jan 2020 20:47:49 GMT
Attorney General William Barr briefly attended a meeting at the Justice Department last fall between top criminal prosecutors and President Donald Trump's personal attorney Rudy Giuliani, a department official said Friday.
Date: Fri, 17 Jan 2020 23:15:26 GMT
No one knows who is going to win the Iowa caucuses in 17 days' time.
Date: Fri, 17 Jan 2020 23:33:43 GMT
Former New York Rep. Chris Collins was sentenced to 26 months in prison on Friday after pleading guilty to federal charges in an insider trading case.
Date: Fri, 17 Jan 2020 23:37:34 GMT

flickr

wcmarengo posted a photo:

Date: 2020-01-18T00:16:26Z
U Bahn Sichtung

Tina Nirschl-Löhr posted a photo:

U Bahn Sichtung

sdr

Date: 2020-01-18T00:16:28Z
HOG 1740 3

southernrailway7000 posted a photo:

HOG 1740 3

Date: 2020-01-18T00:16:28Z

showmeyourknits posted a photo:

Date: 2020-01-18T00:16:38Z
Ashland tournament ‘19

mparseghian1 posted a photo:

Ashland tournament ‘19

Date: 2020-01-18T00:16:38Z
_DSC9784.jpg

Dan Marcolina posted a photo:

_DSC9784.jpg

Date: 2020-01-18T00:15:52Z
Gonzalo Castillo

redesgonzalopresidente posted a photo:

Gonzalo Castillo

Date: 2020-01-18T00:16:09Z
Hoco 2019

xufei.photos posted a photo:

Hoco 2019

Date: 2020-01-18T00:16:35Z

ancestrydetective posted a photo:

Date: 2020-01-18T00:15:49Z
Quotes of Infamous Mark Suckerberg. Move fast with stable infrastructure.

fuckfacebookpro posted a photo:

Quotes of Infamous Mark Suckerberg. Move fast with stable infrastructure.

via Tumblr ift.tt/38o6rol

Date: 2020-01-18T00:16:02Z

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)

Comment form

Please type the word 'Liverpool' here:

BB code available :

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