<?php dl("simplexml.so"); date_default_timezone_set('PRC');//北京时区 $Btime = microtime(true); $arrStarName = array("swingbj","donghae861015"); //声明xml文件 $string = <<<XML <?xml version='1.0' encoding="UTF-8"?> <statuses> </statuses> XML; $localtime = date('y-m-d H:i:s',strtotime(" -96 hour"));//前一小时 $strlocal = strtotime($localtime);//转化为时间戳 foreach($arrStarName as $v) { $newxml = simplexml_load_string($string); $strUrl = "http://twitter.com/statuses/user_timeline/".$v.".xml"; $strContent = file_get_contents($strUrl); if ($strContent === false) { echo "link error;"; exit; } $iNum = file_put_contents("textxml/old_".$v.".xml",$strContent); //parse xml $xml = simplexml_load_file("textxml/old_".$v.'.xml'); $k = 0; foreach($xml->status as $status) { $picTag = "http://twitpic.com/"; $iPid = 0; //处理不同图片服务器的图片twitpic plixi yfrog if (preg_match("/http\:\/\/twitpic.com/",$status->text))//twitpic图片 { $iPosion = stripos($status->text,$picTag); $iPid = substr($status->text,$iPosion+19,6); $strPicUrl = "http://twitpic.com/show/large/".$iPid; $strPic = file_get_contents($strPicUrl); $filename = "images/".$v; if(!file_exists($filename)) { mkdir($filename,0777); } file_put_contents("images/".$v."/".$iPid.".jpg",$strPic); } elseif(preg_match("/http\:\/\/yfrog.com\//",$status->text))//yfrog图片 { $iNum = stripos($status->text,"http://yfrog.com/"); $iPid = substr($status->text,$iNum+17,6); $strPicUrl = "http://yfrog.com/".$iPid.":iphone"; $strPic = file_get_contents($strPicUrl); $filename = "images/".$v; if(!file_exists($filename)) { mkdir($filename,0777); } file_put_contents("images/".$v."/".$iPid.".jpg",$strPic); } elseif(preg_match("/http\:\/\/plixi.com\//",$status->text))//plixi图片 { $iNum = stripos($status->text,"http://plixi.com/",$status->text); $iPid = substr($status->text,$iNum+17,7); $strPicUrl = "http://api.plixi.com/api/tpapi.svc/imagefromurl?size=big&url=http://tweetphoto.com/".$iPid; $strPic = file_get_contents($strPicUrl); $filename = "images/".$v; if(!file_exists($filename)) { mkdir($filename,0777); } file_put_contents("images/",$v."/".$iPid.".jpg",$strPic); } else { $iPid = ""; } //get the nmessage of one hours $time = date('y-m-d H:i:s',strtotime($status->created_at)); $sendtime = strtotime($time); if($sendtime > $strlocal) { $newxml->status[$k]['tid'] = $status->id; $newxml->status[$k]['text']= $status->text; $newxml->status[$k]['created']=$status->created_at; $newxml->status[$k]['image'] = $iPid===""?'':"images/".$v."/".$iPid.".jpg"; $newxml->status[$k]['source']= $status->source; } $k++; } $newxml->asXml("textxml/".$v.".xml");//生成新xml文件 if(file_exists("textxml/old_".$v.".xml"))//删除原xml文件 { unlink("textxml/old_".$v.".xml"); } } $Etime = microtime(true); $useTime = $Etime - $Btime; echo "save ok use time:".$useTime; ?>?