【发布时间】:2010-11-22 11:10:57
【问题描述】:
我有我正在开发的应用程序的代码:
<?php
header("Content-type: text/xml");
//Gather data and prepare query
$thequery = urlencode($_GET['s']);
$yhost = 'http://boss.yahooapis.com';
$apikey = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$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);
$data = str_replace( array('<abstract>', '</abstract>'), array('<description>', '</description>'), $data);
$results = new SimpleXmlElement($data, LIBXML_NOCDATA);
//echo the results
echo $results->asXML();
?>
我在哪里有这一行:$thequery = urlencode($_GET['s']); 我想将它记录到数据库中,但显然输出 XML 非常重要,所以我如何确定,如果 mysql 位由于某种原因失败,XML仍然被输出?还是我过于复杂了?
【问题讨论】: