09-17-2007, 01:35 PM
|
#6 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
I just love how simple (pardon the pun) SimpleXML is to use. When comparing it to the nasty old days of parsing manually through an XML document, using SimpleXML is almost child's play.
PHP Code:
/* Challenge: Output the title and author of the latest post within the Tips & Tricks forum on TalkPHP, in two lines of code. (Code can be wrapped for readability) */
$rss = new SimpleXMLElement( 'http://www.talkphp.com/external.php?lastpost=1&forumids=10', LIBXML_NOCDATA, true); printf('<p><strong>%s</strong> by %s</p>', $rss->channel->item[0]->title, $rss->channel->item[0]->children('http://purl.org/dc/elements/1.1/')->creator);
The complicated children() line above is just to access a namespaced node ( dc:creator) -- it's nothing scary. The LIBXML_NOCDATA flag will likely be the subject of an article/post here sooner or later.
Last edited by Salathe : 09-17-2007 at 02:14 PM.
|
|
|
|