Php 将多个twitter配置文件保存到单个xml文件

Php 将多个twitter配置文件保存到单个xml文件,php,xml,twitter,Php,Xml,Twitter,嗨,我正在努力为一个客户识别关键的Twitter影响者,我有一个170个Twitter id的列表,我需要了解更多 我想让脚本在Twitter Id列表中循环,并将输出保存到一个XML文件中- 等 本质上,我需要编写一个脚本来传递每个url,并将输出保存为服务器上的单个xml文件。关于如何使用PHP实现这一点,我需要使用Curl吗 谢谢你的帮助 干杯 Jonathan这是一个简单的示例,说明了如何使用cURL实现这一点: // array of twitter accounts $ids

嗨,我正在努力为一个客户识别关键的Twitter影响者,我有一个170个Twitter id的列表,我需要了解更多

我想让脚本在Twitter Id列表中循环,并将输出保存到一个XML文件中-

本质上,我需要编写一个脚本来传递每个url,并将输出保存为服务器上的单个xml文件。关于如何使用PHP实现这一点,我需要使用Curl吗

谢谢你的帮助

干杯


Jonathan

这是一个简单的示例,说明了如何使用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);
//twitter帐户数组
$ids=数组('mattmuller','welovecrowds','jlyon'/*(…)*/);
$ch=curl_init();
$url='1http://twitter.com/users/show/';
$xml='';
//使curl返回内容,而不是输出内容
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
foreach($id作为$id){
//根据帐户id设置url
curl_setopt($ch,CURLOPT_URL,“$URL$id.xml”);
//获取url内容并删除xml标题
$xml.=preg\u replace('/\/i','',curl\u exec($ch));
}
//将$xml的内容保存到文件中
文件内容('users.xml',$xml);

WTF-你在开玩笑吧!!!!这就像一个魅力-非常感谢你!!!!!!!!!!!!!!!!!!!只需要一个简单的问题,我是否需要以不同的结构构建xml模式,以便在excel中打开它?就目前的结构而言,它抛出了一个错误,但是如果我在xml中只有一个用户,它就可以了——有什么想法吗?感谢Jonathan不知道Excel如何处理纯XML文件,但如果您想使其真正可移植,可以将其转换为CSV: