我使用以下代码输出显示的xml中的所有节点。
$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");
我回来的只有Array ( [0] => [1] => [2] => )
下载xml的样本
http://twitter.com/statuses/followers/barakobama.xml?cursor=-1
我做错了什么?每个人都建议的一切都没有奏效!我疯了。
答案 0 :(得分:5)
您需要:
$id = $user['id'];
或
$id = $user->attributes()->id;
见basic usage of SimpleXML。你正在做的不是查询属性的有效方法。
答案 1 :(得分:1)
$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;
该XML中没有next_link
或prev_link
,我假设您在谈论previous_cursor
和next_cursor