Forum Moderators: open

Message Too Old, No Replies

Magpie RSS

         

shimeal

2:09 am on Dec 15, 2005 (gmt 0)

10+ Year Member



I am an RSS newbie and am totally confused by something that seems to be to be simple. What I am trying to accomplish is this...

I have an RSS feed coming from Example.com which I am displaying on my blog. The problem is that I can't understand how to parse this information into the format I want to use. A portion of the feed that I am receiving from Example.com in RSS 2.0:

<item>
<title>Brian's Birthday</title>
-
<link>
....blah blah blah
</link>
-
<description>
....blah blah blah
</description>
<pubDate>Tue, 15 Aug 2006 05:00:00 GMT</pubDate>
-

I am using a magpie RSS reader to try and parse and display a portion of this information on my blog. The code inside of my ExpressionEngine/PMachine magpie RSS reader looks like this:

{exp:magpie url="http://www.example.com/rss/feed.asp?e=16591&k=efbc03446478901b90f5ea032f2e4c99" limit="2" refresh="720"}
<ul>
{items}
<li>{title}{description}</li>
{/items}
</ul>
{/exp:magpie}

Whew - What I am trying to do is simply have the <title> and the <pubDate> WITHOUT THE TIME CODE displayed.

IOW, like this: Brian's Birthday Tue, 15 Aug 2006

I cannot figure out how to do this. How can I parse out the <pubDate> and display just the the portion of the <pubdate> shown above i.e. without the time code?

Am I totally off-track? As I said, I am new to RSS and can't seem to find an answer after spending several hours searching various forums...

Please advise!

[edited by: werty at 2:11 pm (utc) on Dec. 15, 2005]
[edit reason] Changed urls to Example.com. Please see TOS #13 [/edit]

twist

10:36 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your going to have to use php to parse the feed. Look into regular expressions. I had a lot of trouble when I first tried parsing a feed. Here is an example of how I parse a weather feed. Sorry if I made any mistakes.

A section of a rss feed with current weather conditions,

- <item>
- <title>
Overcast and 21 degrees F at Location, State
</title>
<link> http://example.gov/ </link>
- <description>
Winds are Calm. Last Updated on Dec 15, 12:55 pm PST.
</description>
</item>

Here is how I parse it,


require_once( 'rss_fetch.inc' );
// Include magpie

$rss = fetch_rss('http://example.com/current_weather_conditions.rss');
// Grab RSS feed and store into variable

$item = $rss->items[0];
// Split and store rss into the $item array

$title = $item[ 'title' ];
// Grab and store the title section from the RSS feed

preg_match( '/[0-9]+/', $title, $matches );
// Parse the title text for numbers and store them in the $matches array

$conditions = explode( "and", $item[ 'title' ], 2 );
// Split apart title grabbing and storing text before the word "and"

$conditions = trim( $conditions[0] );
// Trim off any whitespacs

$weather = $matches[0] .'&deg; F and '. strtolower( $cond );
// Put it all together

echo 'Weather: '. $weather;

displays,

Weather: 21° F and overcast