【问题标题】:Yahoo BOSS Query雅虎BOSS查询
【发布时间】:2010-03-28 10:07:44
【问题描述】:

我不想回应 totalresults 但有些人认为是错误的。

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

        }

谁能帮帮我

【问题讨论】:

  • 什么不起作用?问题是什么?您收到什么错误消息?

标签: php json yahoo-boss-api


【解决方案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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 2015-06-20
    相关资源
    最近更新 更多