0

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?

Carl Smotricz
  • 66,391
  • 18
  • 125
  • 167
thisisready
  • 623
  • 2
  • 10
  • 22

2 Answers2

1

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
  • 3,760
  • 21
  • 23
1

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
  • 1,449
  • 12
  • 12
  • 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 Aug 01 '10 at 11:28