2012-05-12 47 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);