Add the What The Duck comic strip to your website using PHP

If you’d like to add the hilarious comic strip What The Duck to your website, here is a quick and easy solution using PHP.

First, we need a function that will fetch the What The Duck RSS feed and parse it into an array from which we can extract what data we want.  This function, below, is called getWhatTheDuck() .

Second, we need another function that will take that array of data and format it.  We can display just the latest comic strip or any number up to the total featured in the RSS feed.

For the purposes of this sharing of knowledge, the code will loop through the array and output everything that’s available.  It should be a simple matter to change the loop to go through only once if you only want to display the latest strip.

See the PHP code

See the PHP script in action

Download the PHP script

About James Quinn-Hawtin
James Quinn-Hawtin has ten years experience working in the Internet industry. He currently owns and manages WEBNERD, a web design & development company based in Brisbane, Australia, and lectures at Queensland University of Technology in the E-Commerce unit.

Comments

  1. Meethil says:

    Hi, I am trying to use your PHP script to embed WTD in my website. But when i ran the script i say that it brings up WTD 450 as the first comic strip and then WTD 687 – WTD 690 (the real latest)

    Isnt there an error in the script. Why should it bring up WTD 450 at all, its not among the last few. Can you please tell me of some way in which i can get a latest version of WTD to show up on my website. I would also like to resize the strip to fir a particular area and make it clickable so that visitors can go to the original WTD site.

    I have asked Aaron Johnson for his permission and he recommended your script when i suggested he upload WTD twice so that people can hot link to the latest strip.

    Please help. Thanks. Best regards, meethil

Speak Your Mind

*