我正在使用PHP和高音揚聲器RSS來分析推文並嘗試將推文存儲在數據庫中。我怎樣才能得到比上次檢查最近的推文?
有沒有什麼辦法,我只能得到/解析最近的推文比上次分析或檢查?因爲時不時的微博RSS上可能會有推文更新。
function fetch_rss_tweets($username, $maxtweets) {
//Using simplexml to load URL
$tweets = simplexml_load_file("http://twitter.com/statuses/user_timeline/" . $username . ".rss");
$tweet_array = array(); //Initialize empty array to store tweets
foreach ($tweets->channel->item as $tweet) {
/* print '<pre>';
print_r ($tweet);
print '</pre>';*/
//Loop to limitate nr of tweets.
if ($maxtweets == 0) {
break;
} else {
$twit = $tweet->description; //Fetch the tweet itself
//Remove the preceding 'username: '
$twit = substr(strstr($twit, ': '), 2, strlen($twit));
// Convert URLs into hyperlinks
// $twit = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a href=\"\\0\">\\0</a>", $twit);
// Convert usernames (@) into links
$twit = preg_replace("(@([a-zA-Z0-9\_]+))", "<a href=\"http://www.twitter.com/\\1\">\\0</a>", $twit);
// Convert hash tags (#) to links
$twit = preg_replace('/(^|\s)#(\w+)/', '\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>', $twit);
//Specifically for non-English tweets, converts UTF-8 into ISO-8859-1
$twit = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $twit);
//Store tweet and time into the array
$tweet_item = array(
'desc' => $twit,
);
array_push($tweet_array, $tweet_item);
$maxtweets--;
}
}
//Return array
return $tweet_array;
}
從數據庫中檢索最新的行並將其與每個RSS源項目比較,直到你得到一個較舊的,比你已經有了? – zerkms
這是我現在正在做的,但我的客戶說,有沒有辦法檢查最近的鳴叫 – logudotcom
沒有rss接受任何參數? – zerkms