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

Link to comment
Share on other sites

the thing is, i dont actually want to use addfeed() and print the category's feed, i just want to extract the last date, which i am using in another script to generate the time since the last update to the category feed.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

 

Link to comment
Share on other sites

thank you both, i just figured out the XPATH, and with a few functions and queries working together, i have solved the problem. and ignace, yes, that is what i meant. "computer science" has always seemed so vague. thanks aagain

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.