开发者

save multiple twitter profiles to single xml file

开发者 https://www.devze.com 2023-01-02 00:26 出处:网络
Hi I am trying to identify key Twitter influencers for a client and I have a list of 170 twitter id\'s that I need to learn more about.

Hi I am trying to identify key Twitter influencers for a client and I have a list of 170 twitter id's that I need to learn more about.

I would like the script to loop through the list of Twitter Id's and save the output to a single XML file -

http://twitter.com/users/show/mattmuller.xml

http://twitt开发者_如何转开发er.com/users/show/welovecrowds.xml

http://twitter.com/users/show/jlyon.xml

etc

In essence I need to write a script that passes each url and saves the output as a single xml file on the server. Any ideas on how to do this with PHP and do I need to use Curl?

Thanks for any help.

Cheers

Jonathan


This is a simple example of how could you achieve this using cURL:

// array of twitter accounts
$ids = array('mattmuller', 'welovecrowds', 'jlyon' /* (...) */);    

$ch = curl_init();
$url = 'http://twitter.com/users/show/';
$xml = '<?xml version ="1.0" encoding="utf-8"?>';

// make curl return the contents instead of outputting them
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

foreach($ids as $id) {
    // set the url base on the account id
    curl_setopt($ch, CURLOPT_URL, "$url$id.xml");
    // fetch the url contents and remove the xml heading
    $xml .= preg_replace ('/\<\?xml .*\?\>/i', '', curl_exec($ch));
}

// save the contents of $xml into a file
file_put_contents('users.xml', $xml);
0

精彩评论

暂无评论...
验证码 换一张
取 消