2012-05-12 99 views
-2

我正在嘗試從下面的頁面獲取內容。出於我自己的目的,我只是對標籤感興趣,然後我可以將它放入數組中,以便當我使用適當的方法將機器人響應發送回Twitter API時。下面是我的嘗試:試圖使用php獲取網頁的內容

  <?xml version="1.0" encoding="ISO-8859-1"?> 
     <conversation convo_id="$convo_id"> 
     <bot_name>infobot2012</bot_name> 
     <user_name>User</user_name> 
     <user_id value='2' /> 
     <usersay>$say</usersay> 
     <botsay>Internal error detected. Please inform my botmaster. </botsay> 
     </conversation> 


     $url = "http://localhost/Program-O/chatbot/conversation_start.php?say=$say& 
     hello&convo_id=$convo_id&bot_id=$bot_id&format=xml"; 

     get_url_contents($url) 
     $crl = curl_init(); //getting Parse error: syntax error, unexpected T_VARIABLE 
     $timeout = 5; 
     curl_setopt ($crl, CURLOPT_URL,$url); 
     curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); 
     $ret = curl_exec($crl); 
     curl_close($crl); 
     return $ret; 

回答

0

你錯過了在它上面的線分號:

get_url_contents($url) 

應該

get_url_contents($url); 
+0

誰低估了這個?爲什麼? –

+0

隨機downvote的喜悅,它不是我的方式只是在這裏讓你知道我也喜歡這些:) – Dale

0

試試這個:

function get_url_contents($url) { 
    $crl = curl_init(); 
    $timeout = 5; 
    curl_setopt ($crl, CURLOPT_URL,$url); 
    curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); 
    $ret = curl_exec($crl); 
    curl_close($crl); 
    return $ret; 
} 

$url = "http://localhost/Program-O/chatbot/conversation_start.php?say=" . $say . "&hello&convo_id=" . $convo_id . "&bot_id=" . $bot_id . "&format=xml"; 

echo get_url_contents ($url);