SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist mdew_junkie's Avatar
    Join Date
    Mar 2004
    Location
    USA
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with RSS parsing with PhP

    Hello,

    I'm hoping someone can help me with a PhP script I've been trying to get to work. I have magpie RSS installed on my server and am trying to use it to display data from an RSS xml feed. I initally managed to get a crude version to work which would only display the title of the article as a link to the original page.

    I am trying to get something more advanced so that the php code pulls, the title, link of the article, date and then part of the description and displays it as:

    <a href="link">title</a>, month/day/year -- description
    <a href="link">title</a>, month/day/year -- description
    etc..

    I would also like to be able to limit the size of the description to the first 100 characters.

    Can anyone help? I'm completely new at Php and have been stumbling along trying to get this to work.

    Thanks!!

    Here's my coding attempt:
    <?php
    include('rss/rss_fetch.inc');
    $url = "http://www.voanews.com/english/customCF/RecentStoriesRSS.cfm?keyword=TopStories";
    $rss_data = fetch_rss($url);
    if ($rss) {

    foreach ($rss_data->items as $rss_item ) {
    $rss_title = $rss_item['title'];
    $item_link = $rss_item['link'];
    $rss_pubDate = $rss_item['date_timestamp'];
    $rss_description = $rss_item['description'];
    echo "<p><a href=$item_link>$rss_title</a> - " . date("m/d/Y", $rss_pubDate) . " - ". $rss_description ."\n";
    }
    }
    ?>
    Last edited by mdew_junkie; Feb 26, 2009 at 15:57. Reason: cleaned up code error

  2. #2
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    str_word_count and substr should be adequate for getting the description to 100 chars or less. I say or less because you probably don't want to cut a word off exactly at the 100th char if it is in the middle of a word.
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!


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
  •