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

时间:2011-05-10 11:21:50

标签: php xml rss

致命错误:在堆栈跟踪中消息'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>';

?>

请帮帮我...

1 个答案:

答案 0 :(得分:0)

尝试更改

$link=strip_tags($link);

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

看起来空间可能导致错误