SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
Thread: Problem using Sitepoint feeds
-
Dec 15, 2004, 15:45 #1
Problem using Sitepoint feeds
Hi there -
I'm trying to publish a number of newsfeeds together to provide recent news for UK businesses online.
I figured the SitePoint blogs would be a good source of information on web design news.
However, I can't get the feed to work on the page.
I've tried two sets of PHP code, which works on most feeds, but for some reason doesn't work with a couple - and SitePoint is one of them.
Here's the current code I'm running on each feed:
Code:<?php $xmlfile = file_get_contents ("http://www.sitepoint.com/blogs.rdf"); if (empty($xmlfile)) die("failed to connect to xml feed"); preg_match_all("|<item>(.*)</item>|sU", $xmlfile, $items); $itemlist = array(); foreach ($items[1] as $key => $item) { preg_match("|<title>(.*)</title>|s", $item, $title); preg_match("|<link>(.*)</link>|s", $item, $link); $itemlist[$key]['title'] = $title[1]; $itemlist[$key]['link'] = $link[1]; } // Display all article titles, linking them to the actual story foreach ($itemlist as $item) { echo '<a href="' . $item['link'] . '">' . $item['title'] . '</a><br>'; } $xmlfile = ""; // empty out the xmlfeed variable so that you can test the next one. ?>
Is there any obvious reason why I can't call up the SitePoint blogs feed?Internet Business Forums - free business help & advice
-
Dec 18, 2004, 07:15 #2
Is it too technical a question - or have I posted it in the wrong section?
Internet Business Forums - free business help & advice
-
Dec 18, 2004, 10:29 #3
- Join Date
- Dec 2003
- Location
- Federal Way, Washington (USA)
- Posts
- 1,524
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi Brian,
I was actually going to post a response yesterday but didn't know if I was really knowledgeable enough about the problem to be able to help.
If you put a die($xmlfile); statement right after the very first statement in your script, then go view the source for your output, you'll see that the feed elements are not just within <item></item> tags, which says to me that you probably have to change your regular expression to capture them properly. I'm regular-expression-challenged, so I'm not sure exactly how you'd want to change that to get your code to work.
You might want to post this in the PHP forum. I'm sure someone from there could help.
Sorry you didn't get a reply sooner.Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web
-
Dec 18, 2004, 23:29 #4
- Join Date
- Dec 2003
- Location
- Federal Way, Washington (USA)
- Posts
- 1,524
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just a follow-up to my earlier post. You might have already figured this out, but here's how your code needs to change to be able to parse that newsfeed. Change this line of code:
Code:preg_match_all("|<item>(.*)</item>|sU", $xmlfile, $items);
Code:preg_match_all("|<item (.*)</item>|sU", $xmlfile, $items);
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web
-
Dec 20, 2004, 06:09 #5
Superb work, vinyl junkie - you're a star.
Make sure that noe of the sP admins gives you a big star for that.
Many thanks indeed - I can now promote SP from my site.Internet Business Forums - free business help & advice
-
Dec 20, 2004, 07:24 #6
- Join Date
- Dec 2003
- Location
- Federal Way, Washington (USA)
- Posts
- 1,524
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Aw gosh, you're making me blush.
Hey, I thought of something else on that one statement after I finally figured it out. If you change it to this:
Code:preg_match_all("|<item(.*)</item>|sU", $xmlfile, $items);
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web
-
Feb 11, 2005, 02:31 #7
- Join Date
- Feb 2002
- Location
- Auckland
- Posts
- 14,692
- Mentioned
- 20 Post(s)
- Tagged
- 3 Thread(s)
Vinyl,
Good work!
Hmmm, chasing about with this "thread" on RSS parsing and still can't get to the enclosure tag of RSS 2.0! Oh, well, at least there is a way to get to it with this code. Thanks for the link to this thread!
Regards,
DKDavid K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
-
Feb 11, 2005, 08:36 #8
Shouldn't you be using XML parsers or XSLT instead of regular expressions to transform RSS feeds? Seems like regex could open up a whole host of other issues...
-
Feb 11, 2005, 15:19 #9
- Join Date
- Feb 2002
- Location
- Auckland
- Posts
- 14,692
- Mentioned
- 20 Post(s)
- Tagged
- 3 Thread(s)
Vinnie,
Originally Posted by vgarcia
Do you know of any program that can read RSS 2.0 feeds and download their enclosures?
THANKS!
Regards,
DKDavid K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
-
Feb 11, 2005, 15:24 #10
Well, PHP4's main issue is that XML/XSLT processors are extensions and most hosts won't have them enabled. You might be better off with regex if most of the webmasters you're working with are using PHP4.
-
Feb 11, 2005, 16:16 #11
- Join Date
- Feb 2002
- Location
- Auckland
- Posts
- 14,692
- Mentioned
- 20 Post(s)
- Tagged
- 3 Thread(s)
Vinnie,
Okay, THANKS!
Regards,
DKDavid K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
Bookmarks