简体   繁体   English

使用PHP从Yahoo BOSS API输出XML

[英]output XML from Yahoo BOSS API with PHP

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);
$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? 那么,我究竟如何输出实际的XML而不是HTML?

Tried this: 试过这个:

echo $results->asXML();

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM