Working with RSS + PHP - Printable Version +- howtothings.co.uk (https://www.howtothings.co.uk) +-- Forum: Computing (https://www.howtothings.co.uk/forumdisplay.php?fid=4) +--- Forum: Website Development, Implementation and General Webmaster Support (https://www.howtothings.co.uk/forumdisplay.php?fid=9) +--- Thread: Working with RSS + PHP (/showthread.php?tid=104) |
Working with RSS + PHP - Drumm - 08-06-2010 For a long time, I struggled to get RSS to play nicely with PHP. After much research and revising PHP, I finally got some script that works. The first thing to realise is that RSS is just XML, if you'd like to learn more about XML head over to http://www.w3schools.com I will walk you through how my code works. PHP Code: <?php The rest basically loads the feed into a variable that we can now edit. So we carry on. PHP Code: <?php Lets start with PHP Code: $post = $xmlDoc->getElementsByTagName( "item" ); Now lets examine part of the foreach loop, from which you can work out the rest of it. The rest of the foreach that I show you will examine the Title tag, but it can be applied to the others with a few small changes. PHP Code: $Titles = $item->getElementsByTagName( "title" ); PHP Code: $Title_Array[$value] = $Title; Note: When getting tags, please note that they are case-sensitive. Until Next Time -Drumm RE: Working with RSS + PHP - CrazyT - 08-06-2010 That would most probably (will) take longer than using preg_match(). RE: Working with RSS + PHP - Drumm - 08-06-2010 I chose this method because it allows me slightly more control, I haven't had any problems. It isn't intended for any extremely heavy use, and It could easily be optimised. I don't pretend to be a PHP Expert, if you PM me any changes you see fit, I will happily incorporate them + give credit where due. Also, quoting a huge post like that can be a pain, I know it isn't against forum rules, but it isn't exactly.. Nice ? To go through all that crap first. It's much appreciated. -Drumm |