未捕获的异常“异常”,消息“字符串无法解析为第 48 行的 XML


Uncaught exception 'Exception' with message 'String could not be parsed as XML on line 48

致命错误:堆栈跟踪中未捕获的异常"异常",消息"字符串无法解析为 XML":C:''xampp''htdocs''trendfeeds.php(48):在第 48 行抛出的 SimpleXMLElement->__construct('') {main}

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>';
?>

请帮帮我...

尝试更改

$link=strip_tags($link);

$link=urlencode(strip_tags($link));

看起来空间可能会导致错误