tags:

views:

23

answers:

1

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://twitter.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

+1  A: 

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);
nuqqsa
WTF - ARE YOU KIDDING ME!!!! That works like a charm - thank you so much!!!!!!!!!!!!!!!!!!!
Jonathan Lyon
just one quick question, do I need to structure the xml schema differently in order to open it in excel? at the moment as the structure is<user></user><user></user>it throws an error but if I have only one user in the xml it is fine - any ideas?ThanksJonathan
Jonathan Lyon
Not sure how Excel handles plain XML files, yet if you want to make it really portable you can convert it to CSV: http://codestips.com/php-xml-to-csv/
nuqqsa