Jump to content

[SOLVED] getting the last RSS pubDate from a selected feed


hchsk

Recommended Posts

i have a dynamically generated RSS.php which i categorically link to on my website with this code:

 

<?php

function addfeed($feed){

$doc = new DOMDocument();
$doc->load('http://www.lowersouthlounge.com/updates.php');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
	$itemRSS = array ( 
		'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
		'cate' => $node->getElementsByTagName('category')->item(0)->nodeValue,
		'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
		'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
		'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
		);
	array_push($arrFeeds, $itemRSS);
}



for ( $counter = 0; $counter <= count($arrFeeds); $counter += 1 ) {

if (stristr($arrFeeds[$counter][cate], $feed) != false) {
print '<b>' . $arrFeeds[$counter][title] . '</b><br><small>' . $arrFeeds[$counter][date] . '</small><br><br>';
print '<blockquote>' . $arrFeeds[$counter][desc] . '</blockquote><br><br><br>';

}}

}


?>

 

 

and <?php addfeed('team1') ?>

 

i'm stumped as to how i can get the last pubDate from within that addfeed()

 

 

any help, suggestions, would be greatly apprieciated

wow, thanks, but to be honest, this seems somewhat beyond me, can i ask you to explain it a bit further?

 

say i want to call the value from example.php

 

<?php

include("rssinclude.php");    // script from which addfeed() is called

$last = $xpath->query( '//pubDate[position() = last()]' );

?>

 

how does that work exactly

I don't know if there are degrees in this area - XML. Try googling for "XML degree".

 

Here is a longer code example using XPath:

 

<?php
$doc = new DOMDocument;
$doc->load( 'http://www.lowersouthlounge.com/updates.php' );

// Create an XPath instance with your document
$xpath = new DOMXPath( $doc );

// Get the last pubDate element
$last = $xpath->query( '//pubDate[position() = last()]' )->item( 0 )->nodeValue;
?>

 

 

 

XPath is an query language for XML documents, just in the same way SQL queries databases.

 

There is some good documentation on XPath at W3Schools.

You probably are referring to degrees in php which can be:

 

1) Self-Study webdevelopment is a fast moving thing what is hot today is out tomorrow you need to keep up, the best way in doing this is by subscribing to rss feeds from people in the industry, following what they are doing through twitter and ofcourse make sure they know you! Get involved in open-source programs, create stuff and share it with others to get noticed..

 

The other options are:

 

2) communication and multimedia technology (mostly php and the material is outdated) as teachers like to believe that what they studied in their younger years still applies.. :S

3) computer science - top notch and helps you in understanding computers, what are bits? how are they used? and besides that algorithms, design patterns, and lots and lots more..

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.