开发者

output XML from Yahoo BOSS API with PHP

开发者 https://www.devze.com 2023-01-26 08:02 出处:网络
I managed to get this code so far: <?php //Gather data and prepare query $thequery = urlencode($_GET[\'s\']);

I managed to get this code so far:

    <?php
//Gather data and prepare query
$thequery = urlencode($_GET['s']);
$yhost = 'http://boss.yahooapis.com';
$apikey = 'xxxxxxxxxxxxxxx';
$url = $yhost.'/ysearch/news/v1/'.$thequery.'?appid='.$apikey.'&format=xml';
//Get the results
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);开发者_JAVA百科
$data = curl_exec($ch);
curl_close($ch);
$results = new SimpleXmlElement($data, LIBXML_NOCDATA);
//echo the results
foreach ($results->resultset_news->result as $theresult) {
echo '<a href="'.$theresult->clickurl.'">'.$theresult->title.'</a><br/>';
echo $theresult->abstract.'<br/>';
echo '<small><i>'.$theresult->dispurl.'</i></small><br/>';
echo '<br/><br/>';
}

So how exactly do i output actual XML rather than HTML?


Tried this:

echo $results->asXML();

?

0

精彩评论

暂无评论...
验证码 换一张
取 消