我有一个日志文件,用于存储我想在Twitter搜索中运行agasint的搜索词。
我有以下内容基本上搜索1个值,但CSV包含许多要搜索的值。
如何调整以下内容以查找文件:searchterms.txt
读入逗号分隔值,然后独立搜索每个值。
还要将每个搜索保存到自己的文本文件中吗?
<?php
$q=$_GET['q'];
if($_GET['q']==''){
$q = 'tpid1262445133';}
$search = "http://search.twitter.com/search.atom?q=".$q."";
$tw = curl_init();
curl_setopt($tw, CURLOPT_URL, $search);
curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);
$twi = curl_exec($tw);
$search_res = new SimpleXMLElement($twi);
foreach ($search_res->entry as $twit1) {
$description = $twit1->content;
$date = strtotime($twit1->updated);
$message = $row['content'];
echo $twit1->author->uri;
echo " ";
echo $twit1->author->name;
echo " ";
echo $description;
echo "</br>";
}
curl_close($tw);
?>
答案 0 :(得分:1)
$searches = explode(';', file_get_contents('searchterms.txt'));
foreach ($searches as $search) {
$result_array[] = json_decode(file_get_contents('http://search.twitter.com/search.json?q='.$search));
}
print_r($result_array);