2011-07-13 7 views
2

私はこれを理解することができませんので、手を貸すことができます。PHP Twilio App - SMSファイルブレークを含むForeachループ

私はtwilioアプリケーションを作成していますが、このファイル全体がforeachループに含まれています。しかし、それは私のループを壊し続け、それが実行された後には続かない。

これはうまくいきますが、内部に含まれているforeachは実行後も継続しません。

アイデア?

おかげで、 ニック

<?php 
//shorten the URL 
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$ebay_url); 

    // Include the PHP TwilioRest library 
    require "twilio/twilio.php"; 

    // Twilio REST API version 
    $ApiVersion = "2010-04-01"; 

    // Set our AccountSid and AuthToken 
    $AccountSid = "removed"; 
    $AuthToken = "removed"; 

    // Instantiate a new Twilio Rest Client 
    $client = new TwilioRestClient($AccountSid, $AuthToken); 

    // make an associative array of server admins 
    $people = array(
     "removed"=>"Nick", 
     //"4158675310"=>"Helen", 
     //"4158675311"=>"Virgil", 
    ); 

    // Iterate over all our server admins 
    foreach ($people as $number => $name) { 

     // Send a new outgoinging SMS by POST'ing to the SMS resource */ 
     // YYY-YYY-YYYY must be a Twilio validated phone number 
     $response = $client->request("/$ApiVersion/Accounts/$AccountSid/SMS/Messages", 
      "POST", array(
      "To" => $number, 
      "From" => 'removed', 
      "Body" => 'Alert! '.$title.' found for '. $price. '. View the item here: '.$tinyurl, 
     )); 
     if($response->IsError) 
      echo "Error: {$response->ErrorMessage}\n"; 
     else 
      echo "Sent message to: {$response->ResponseXml->SMSMessage->To}\n"; 
    } 

?> 

答えて

4

は、私はこの問題は、forループ内で必要とやっていることだと思います。オブジェクトにはtwilio libraryが定義されているので、2回目にそれを要求すると、クラスが再び定義され、エラーがスローされます。

error_reporting(E_ALL)が設定されている場合は、出力にそのエフェクトの例外が表示されます。

私はそれをrequire_onceに変更するか、forループから移動します。

私は役立つことを願っています。

+0

ありがとうございました。 –