views:

341

answers:

3

I want to extract the blog content from my Posterous blog using the API call of http://posterous.com/api/readposts?hostname=NAMEOFSITE

When entering the above address in a web browser, it returns the content in XML format.

What I'm stuck on is how I can use or store this content in an array so I can output it using PHP in the format that I want to display it in?

+1  A: 

Use PHP's OOP SimpleXML:

IBM Developerworks Tutorial: http://www.ibm.com/developerworks/library/x-simplexml.html

PHP Docs: http://php.net/manual/en/book.simplexml.php

PHP Examples: http://www.php.net/manual/en/simplexml.examples-basic.php

CodeJoust
+1  A: 

I did exactly what you are trying achieve for my post.ly helper application. It uses SimpleXML to parse the result of the Posterous API call and display a list of posts with post.ly links and number of views:

$root = simplexml_load_string($xml);
foreach ($root->post as $node)
{
 $url = $node->url;   
 $date = date("Y-m-d H:i", strtotime($node->date));
 $title = $node->title;
 $views = $node->views;
 echo "$date - <a href=\"$url\">$title</a> ($views views)<br />\n";
}

Check out the simplified source code of my application if interested.

Lukas Pokorny
Note: if you're on php4, you're going to need http://www.ister.org/code/simplexml44/index.html, and simplexml_load_string is going to need to be modified a little bit.
AlexeyMK
A: 

has anyone figured this one out? i've been trying to find a quick script that I can use but no avail...

j2eee