tags:

views:

127

answers:

2

Im using the following code to output all the nodes from the xml shown.

  $cursor = "?cursor=-1"
  $xml= new SimpleXmlElement($to->OAuthRequest('http://twitter.com/statuses/followers.xml?$cursor'));
  foreach ($xml->xpath('/users_list/users/user') as $user) {
      $id = $user->id;
      $names .= $user->screen_name;
      $profimg = $user->profile_image_url;
  }
  $next = $user->next_link;
  $prev = $user->prev_link;
  $pusharray = array("$names", "$next", "$prev");

All i get back is Array ( [0] => [1] => [2] => )

Heres a sample of the xml
http://twitter.com/statuses/followers/barakobama.xml?cursor=-1

What am i doing wrong? Everything everyone has suggested has not worked! Im going insane.

+5  A: 

You need either:

$id = $user['id'];

or

$id = $user->attributes()->id;

See basic usage of SimpleXML. What you're doing isn't a valid way of querying an attribute.

cletus
returns nothing. Tried both.
Patrick
It returns nothing because there is _no_ "id" attribute in the source XML. No idea why you accepted that answer, seems random.
Josh Davis
Because it addresses the problem: querying attributes the wrong way.
cletus
+1  A: 
$users_list = simplexml_load_file('http://twitter.com/statuses/followers/barakobama.xml?cursor=-1');

foreach ($users_list->users->user as $user)
{
    echo $user->id, ' ', $user->screen_name, ' ', $user->profile_image_url, "<br />\n";
}

echo 'prev: ', $users_list->previous_cursor, ' - next: ', $users_list->next_cursor;

There is no next_link or prev_link in that XML, I assume you're talking about previous_cursor and next_cursor

Josh Davis