开发者

How do i write in a file the data from GAPI?

开发者 https://www.devze.com 2023-03-23 11:41 出处:网络
I´me us开发者_JS百科ing GAPI (Google Analytics PHP Interface) to get the most searched keywords in my website. This code works ok

I´me us开发者_JS百科ing GAPI (Google Analytics PHP Interface) to get the most searched keywords in my website. This code works ok

$ga->requestReportData(id, array('searchKeyword'), array('searchUniques'),array('-searchUniques'),null,null,null,1,12  );


foreach($ga->getResults() as $result)
{
 echo ' '. $result .'   '.$result->getSearchUniques().'<br/> ' ;
}

But I would like the output to be written on a file....


$fp = fopen('results.txt', 'w');
$ga->requestReportData(id, array('searchKeyword'), array('searchUniques'),array('-searchUniques'),null,null,null,1,12  );


foreach($ga->getResults() as $result)
{
     fwrite($fp, " ". $result ."   ".$result->getSearchUniques()."\n"); 
}


fclose($fp);

Don't forget to create a file named results.txt (or whatever name you want) and chmod it to 777.


$savefile='/your/dir/to/use/ga.txt';

$fh=fopen();
foreach($ga->getResults() as $result)
{
   $line_to_save = ' '. $result .'   '.$result->getSearchUniques()."\n";
   fputs($fh,$line_to_save);
}

fclose($fh);
0

精彩评论

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