致命错误:在堆栈跟踪中消息'String无法解析为XML'的未捕获异常'Exception':C:\ xampp \ htdocs \ trendfeeds.php(48):SimpleXMLElement-> __ construct(''){第48行抛出
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">';
echo '<channel>';
echo '<title>Games - Free Download - Freshwap</title>';
echo '<link>http://www.freshwap.com/</link>';
echo '<language>en</language>';
echo '<description>Games - Free Download - Freshwap</description>';
$url="http://www.google.com/trends/hottrends/atom/hourly";
$beg="<li>";
$end="</li>";
$tryscrape="1";
$end=str_replace('/','\/', $end);
$beg=str_replace('/','\/', $beg);
$end=str_replace('\"','"', $end);
$beg=str_replace('\"','"', $beg);
if($tryscrape==1)
{
$data = file_get_contents($url);
$regex = '/'.$beg.'(.+?)'.$end.'/';
$count=1;
preg_match_all($regex,$data,$match,PREG_SET_ORDER);
foreach ($match as $result) {
$link = $result[1];
$link=strip_tags($link);
echo '<item>';
echo '<title>'.$link.'</title>';
echo '<description><![CDATA[';
?>
<?php
function google_blog_feed($path){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
curl_close($ch);
return $retValue;
}
$sXML = google_blog_feed('http://blogsearch.google.com/blogsearch_feeds?hl=en&q='.$link.'&ie=utf-8&num=10&output=rss');
$oXML = new SimpleXMLElement($sXML); // Error on this line
foreach($oXML->channel->item as $oDocuments){
$title = strip_tags($oDocuments->title);
$url = $oDocuments->link;
$description = $oDocuments->description;
echo $description;
}
?>
<?php
echo ']]></description>';
echo '<category><![CDATA[Google]]></category>';
echo '</item>';
}
}
echo '</channel>';
echo '</rss>';
?>
请帮帮我...
答案 0 :(得分:0)
尝试更改
$link=strip_tags($link);
到
$link=urlencode(strip_tags($link));
看起来空间可能导致错误