그래서 내 웹 사이트에 대해 트위터를 사용하는 사용자를 대상으로하는이 트위터 스크립트에서 작업을 시작했으며,이를 위해 고맙게 여기는 설정을 cron 작업과 함께 설정하려고합니다.배열 변수 값을 하나의 변수에 결합하는 방법
모든 15 명 사용자 이름을 통해 검색 페이지에서 사용자 이름 (총 15)
루프 구문 분석하고 그것 twitter.txt 파일 에있는 경우 스크립트를 중지합니다 : 이것은 어떻게 작동
사용자 이름이 twitter.txt 파일에 없으면 twitter.txt 파일에 사용자 이름을 쓰고 해당 사용자에게 트윗을 보냅니다.
//cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://search.twitter.com/search.atom?q=MYWEBSITE");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$twitter = curl_exec($curl);
curl_close($curl);
//search html source page for user names
preg_match_all('/\<uri\>http\:\/\/twitter\.com\/(.*?)\<\/uri\>/', $twitter, $usernames);
//open the twitter text file and prepare for writing
$twitter = fopen("twitter.txt", "a");
//contents of the twitter text file (holds the twitter user names)
$contents = file_get_contents("twitter.txt");
//loop through each user name
foreach($usernames[1] as $username) {
//if user name is found in the twitter text file it states "Found" and script stops
if (strpos($contents, $username) !== FALSE) {
echo $username . " - <font color=\"red\">Found</font><br />";
//if user name is not found in the twitter text file it records the user name and tweets
} else {
//write to twitter text file
fwrite($twitter, $username."\r\n");
//shows what user names were recorded
echo $username . "<br />";
//user names for tweets
//this is where i need help dividing the usernames into these variables
$usernames_set_one = "";
$usernames_set_two = "";
$usernames_set_three = "";
//tweet
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$content = $connection->get('account/verify_credentials');
//twitter message
$connection->post('statuses/update', array('status' => $usernames_set_one . ' thank you for tweeting about my website.'));
$connection->post('statuses/update', array('status' => $usernames_set_two . ' thank you for tweeting about my website.'));
$connection->post('statuses/update', array('status' => $usernames_set_three . ' thank you for tweeting about my website.'));
return $connection;
}
}
//close the twitter text file no further writing
fclose($twitter);
나는 그 첫 번째 부분에 array_fill()을 사용할 것입니까? – jeff
첫 번째 부분에서는'array_push ($ username_set_one, $ username)'을 사용할 수 있습니다.하지만이 배열 앞에 이미 세 개의 이름이 있는지 확인한 다음 다음 배열로 이동하십시오. 'count ($ username_set_one)'는 그 배열에있는 총 항목을 줄 것이다. – slash197