嘿,我刚做了一个iPhone应用程序,我让用户输入一个搜索词。然后,我将这个搜索词汇发送到我的虚拟主机上的一个PHP页面,然后我查询一些RSS提要并将xml返回到应用程序。我很有趣的做法是将用户搜索词记录到数据库中,然后像平常一样返回XML。显然更重要的是用户得到的是XML而不是记录的术语。那么,我可以添加到下面的代码,以确保XML安全地返回,而不管mysql是否失败?PHP安全地登录到mysql,但如果失败则继续脚本
任何想法?
<?php
header("Content-type: text/xml");
//Gather data and prepare query
$thequery = urlencode($_GET['s']);
$yhost = 'http://boss.yahooapis.com';
$apikey = 'xxxxxxxxxxxxxxxxxxxxxxx';
$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
echo $results->asXML();
?>
谢谢,刚刚实现了这一点,我的应用程序仍然有效。救济 – benhowdle89 2010-12-03 10:32:50
很高兴帮助:) – SW4 2010-12-03 11:35:47