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?
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
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 />
";
}
Check out the simplified source code of my application if interested.