2012-03-10 14 views
-2

私のウェブサイトについてつぶやくユーザーをターゲットとするこのtwitterスクリプトで作業を開始しました。1つの変数に配列の値を組み合わせる方法

  1. は全15ユーザ名による検索ページからユーザ名(計15)

  2. ループ構文解析し、そのtwitter.txtファイル で見つかった場合、それは、スクリプトを停止します。これは、それがどのように動作するかです

  3. twitter.txtファイルにユーザー名が見つからない場合は、 というユーザー名をtwitter.txtファイルに書き込み、そのユーザーにツイートを送信します。 (twitter.txtファイルが同じユーザに重複したツイートの送信を防ぐことができます)

だから私の問題は、このスクリプトは、現在1つの座って15件のツイートを送信し、これはスパムと見なされるだろうということです。だから私は3つのつぶやきにユーザー名を統合できるように助けが必要です。したがって、各ツイートには5つのユーザー名が含まれます。スクリプトの一番下には、つぶやきのユーザー名を格納する変数があります。あなたが代わりにforeachwhile loopを使用して、ユーザ名などにアクセスすることができます

//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); 

答えて

0

$ユーザ名[1] [$ i]は、

$ usernames [1] [$ i + 1];

$ usernames [1] [$ i + 2];例えば

:配列へ

0
$i = 0; 
$count = count($usernames[1]); 
while($i < $count - 3) //we will use $i+2 after all 
{ 

$i++; 
} 

変更これらの3つの変数と最初のものは、第三に、次いで二番目の配列にユーザ名を追加し、完全です。ツイッターに投稿すると、単にimplode()という名前に参加するだけです。

+0

私はその1番目の部分にarray_fill()を使用しますか? – jeff

+0

最初の部分については 'array_push($ username_set_one、$ username)'を使うことができますが、この配列の前に3つの名前があるかどうかを確認してから、次の配列に移動します。 'count($ username_set_one)'は、その配列内の合計項目を返します。 – slash197

関連する問題