0

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?

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
benhowdle89
  • 36,900
  • 69
  • 202
  • 331
  • One glance on the problem, such as `(string) $theresult->clickurl` instead of just `$theresult->clickurl`, and please provide more details on your desired output – ajreal Nov 21 '10 at 13:15
  • I'm trying to return these rss feeds to my iphone app, so i need to output this as xml rather than HTML for a webpage. – benhowdle89 Nov 21 '10 at 13:19
  • the $data is already in xml format, so you want to change some of the details on $data ? – ajreal Nov 21 '10 at 13:35
  • Yes, if you see my comment below Robin's answer... – benhowdle89 Nov 21 '10 at 13:46

1 Answers1

1

Tried this:

echo $results->asXML();

?

Robin
  • 4,242
  • 1
  • 20
  • 20
  • brilliant. say i wanted to change the xml tags for each item. ie. change "abstract" to be called "description" etc. ?? – benhowdle89 Nov 21 '10 at 13:46