2010-03-28 163 views
-1

我想知道回聲totalresults但有些錯誤是錯誤的。雅虎BOSS查詢

// Get search results from Yahoo BOSS as an XML* 
    $API = 'http://boss.yahooapis.com/ysearch/web/v1/'; 
$request = $API . $query .'?format=xml&appid='. APP_ID.'&start='.$start."0"; 

     $ch = curl_init($request); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 
     $xml = simplexml_load_string(curl_exec($ch)); 
     echo $xml->resultset_web->totalhits; 
     // Display search results - Title, Date and URL. 
     foreach ($xml->resultset_web->result as $result) { 

      $ausgabe .= '<a href="'.$result->clickurl.'">'.$result->title.'</a><br />'; 
      $ausgabe .= $result->abstract."<br>"; 
      $ausgabe .= '<a href="'.$result->clickurl.'">'.$result->url."</a> - ".round(($result->size/1024), 2)." Kb<br><br>"; 

     } 

有人可以幫助我

+1

什麼是沒有工作?問題是什麼?你得到什麼錯誤信息? – 2010-03-28 10:45:23

回答

1

在這種情況下,totalhits響應值是resultset_web XML元素的屬性,例如:

[resultset_web] => SimpleXMLElement Object 
    (
     [@attributes] => Array 
      (
       [count] => 4 
       [start] => 0 
       [totalhits] => 79508785 
       [deephits] => 522000000 
      ) 

要訪問attributes from a SimpleXML object,使用attributes()方法像這樣:

echo $xml->resultset_web->attributes()->totalhits;