0

我使用以下代码从显示的 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的示例

我究竟做错了什么?每个人都建议的一切都没有奏效!我要疯了。

4

2 回答 2

5

您需要:

$id = $user['id'];

或者

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

请参阅SimpleXML 的基本用法。您所做的不是查询属性的有效方式。

于 2009-11-08T18:11:50.580 回答
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;

没有next_linkprev_link在那个 XML 中,我假设你在谈论previous_cursornext_cursor

于 2009-11-08T23:00:11.350 回答