hchsk Posted May 2, 2009 Share Posted May 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/ Share on other sites More sharing options...
ignace Posted May 2, 2009 Share Posted May 2, 2009 Won't this do? $doc->getElementsByTagName('pubDate'); Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824311 Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824314 Share on other sites More sharing options...
semlabs Posted May 2, 2009 Share Posted May 2, 2009 Try using XPath: http://uk.php.net/manual/en/class.domxpath.php You can get the last element by using the following query: $last = $xpath->query( '//pubDate[position() = last()]' ); Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824322 Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824325 Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 and out of curiosity, do you have a degree in this work? if so what is the name of the degree? i am very interested in seriously studying this work Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824345 Share on other sites More sharing options...
semlabs Posted May 2, 2009 Share Posted May 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824371 Share on other sites More sharing options...
ignace Posted May 2, 2009 Share Posted May 2, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824402 Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/156557-solved-getting-the-last-rss-pubdate-from-a-selected-feed/#findComment-824436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.