SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SEO Link Building Master I, Brian's Avatar
    Join Date
    Apr 2003
    Posts
    1,284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
     
     ?>
    I'd love to be able to use the feed to publish SitePoint headlines on my site. Any pointers on why I might not be able to?

    Is there any obvious reason why I can't call up the SitePoint blogs feed?
    Internet Business Forums - free business help & advice

  2. #2
    SEO Link Building Master I, Brian's Avatar
    Join Date
    Apr 2003
    Posts
    1,284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it too technical a question - or have I posted it in the wrong section?
    Internet Business Forums - free business help & advice

  3. #3
    $this->toCD-R(LP); vinyl-junkie's Avatar
    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

  4. #4
    $this->toCD-R(LP); vinyl-junkie's Avatar
    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);
    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

  5. #5
    SEO Link Building Master I, Brian's Avatar
    Join Date
    Apr 2003
    Posts
    1,284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    $this->toCD-R(LP); vinyl-junkie's Avatar
    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);
    then your script should work with all your feeds, no matter how they're structured.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 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,

    DK
    David 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

  8. #8
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    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...

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Vinnie,
    Quote Originally Posted by vgarcia
    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...
    Most likely so! However, I've built an RSS feed for a client who wants to get his 28Mb MP3 file out to his site's visitors and I need to be able to tell him/his visitors/their webmasters how to do that. Since I'm not an expert on XML parsers and do know something about parsing with regex (using PHP), I have to stay on semi-familiar ground.

    Do you know of any program that can read RSS 2.0 feeds and download their enclosures?

    THANKS!

    Regards,

    DK
    David 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

  10. #10
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    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.

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Vinnie,

    Okay, THANKS!

    Regards,

    DK
    David 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •