-1

我不想回应总结果,但有些人认为是错误的。

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

        }

有人能帮我吗

4

1 回答 1

1

在这种情况下,totalhits响应值是resultset_webXML 元素上的一个属性,例如:

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

要访问SimpleXML 对象的属性,请使用如下attributes()方法:

echo $xml->resultset_web->attributes()->totalhits;
于 2010-07-05T19:09:28.100 回答