Jane Dallaway

Jane Dallaway

Jane Dallaway  //  Data loving developer/leader/product shaper, storyline curator/creator, life-long learner, photographer, dog owner, reader, crafter, gardener and occasional snowboarder

This blog contains all sorts of odds and ends, from event reviews, stuff about my storyline project, bits of craft, through thoughts on learning, to photography stuff, and general inspiration things. It's a bit all over the place with no real theme, but then so am I!

Email: jane @ dallaway.com
Also at:    

Simple PHP script to output the rss links from an OPML file

My BrightonBloggers site offers an aggregated display of the most recent 50 posts spotted. It uses some php to consume an RSS file which is produced via some yahoo pipes manipulation which takes the OPML file and retrieves RSS from each listed site. Someone reported an error with this yesterday, and after a bit of research it turned out that the yahoo pipes part was timing out. My best guess was that one, or more, of the feeds listed in the OPML file were dead. A quick hunt around google failed to find me anything to do a dead link check from an OPML file, so I quickly cobbled a partial solution - a PHP script to get the RSS links and output to HTML, and then I made use of the firefox add-on LinkChecker to determine which were live or not.

A sample line from my BrightonBloggers OPML file is:

 

<outline type="rss" text="Jane Dallaway" htmlUrl="http://jane.dallaway.com" title="Jane Dallaway" xmlUrl="http://jane.dallaway.com/rss.xml"/>

 
and the php I'm using to consume it and work with it is
 

$file = "http://brightonbloggers.com/brighton.opml";

$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

 

foreach ($lines as $line_num => $line

{

// skip those that don't begin with <outline type="rss"

if (stristr($line,"<outline type=\"rss\"") != FALSE)

{

// find xmlUrl=" and get content between start and end " 

$checkFor = "xmlUrl=\"";

$starter = stripos($line, $checkFor);

if ($starter > 0)

{

$starter = $starter + strlen($checkFor);

}

$end = stripos($line,"\"",$starter);

$xmlurl = substr($line,$starter,$end - $starter); 

//output the link, as a link

    echo "<a href=\"".$xmlurl."\">".$xmlurl."</a><br />\n";

}   

}

After running the dead link checker through firefox, and then pruning or fixing dead links, the aggregated feed is working again

 

Filed under  //  code   php  

Comments (1)

Monty Hall problem - PHP

This evening, after returning from an excellent VBUG: Brighton (of which more in a later post), Richard was talking about the Monty Hall problem after listening to a discussion about it on the BBC podcast In Our Time.

For those who don't know the Monty Hall problem it is this:

  • A gameshow set has 3 doors.
  • Behind one of the doors is a prize.
  • Behind the other 2 doors is nothing.
  • The contestant choses a door.
  • The gameshow hosts, knowing where the prize is, and which door the contestant has chosen, opens a door which he knows hasn't got the prize behind it and the contestant hasn't chosen.
  • The contestant is then offered the opportunity to trade their door for the one remaining door.

Should the contestant switch? The answer is yes 2/3rds of the time. See here for the reasons.

Richard and I both set about proving it in the tools we had available, I chose PHP, Richard chose Scala. And we both can successfully demonstrate that by always switching doors the contestant is more likely to win.

My PHP version is downloadable here.

Filed under  //  code   php  

Comments (0)

A yahoo pipe, some php and a flickr feed

Over on the JaneandRichard home page, we used to show a random image from our image archive. However, to add an image to the archive we needed to register it, and this we failed to do very often. As time went on I was putting photos less often on the JaneandRichard images page, and more often on flickr. So, I updated the front page to use a flickr badge based on my flickr feed. This wasn't ideal, as it didn't combine our output.

Media_httpfarm3static_sxwda

This morning I decided to do a bit of playing, and so produced a yahoo pipe which takes Richard's flickr RSS feed, and my one as an input and returns the most recent image. I then wrote some PHP (well took the Brighton Bloggers aggregated feed PHP actually which in turn was based on the RSS reader produced by Richard Kendall) and wrote out the RSS description within some javascript. This allows me to replace the flickr badge on the home page with an image based on the combined feed.

Media_httpfarm3static_haoos

In order to make this more useful, I used a parameter feed to allow other images to be produced by the script. So, the code
<script type="text/javascript" src="http://jane.dallaway.com/services/getImageFromFlickrRss.php?feed=http://api.flickr.com/services/feeds/photos_friends.gne%3fuser_id=11369209@N00%26friends=0%26display_all=1%26lang=en-us%26format=rss_200"></script>
returns the most recent image added by any of my contacts. The feed parameter needs to have the flickr RSS URL encoded otherwise the script will truncate the output and nothing will be produced.

So here is the output from that script - the latest photo from my contacts:


Update:
There is some cacheing going on at the yahoo pipes end, and so the RSS feed from the pipe doesn't reflect the changes in real time, or as quickly as if you run the pipe manually.

Filed under  //  code   php  

Comments (0)

Brighton Bloggers aggregated RSS

I've just added a new section to Brighton Bloggers to take the last 30 or so blogs from the aggregated RSS feed and display them on the site. Hopefully, for those who don't want to read all the posts via RSS they can still get a flavour of what is on offer from participants.

It is written in PHP and is a customised version of the PHP RSS Reader originally written by Richard James Kendall. The script was really easy to customise and I'm really pleased with how it looks. I could do with a better word than Aggregated though, so if anyone has any suggestions, please let me know.

Filed under  //  Brighton Bloggers   php  

Comments (0)