未捕获的异常“异常”第 48 行显示消息 'String 无法解析为 XML
致命错误:堆栈跟踪中未捕获异常“异常”,消息“字符串无法解析为 XML”:C:\xampp\htdocs\trendfeeds.php(48): SimpleXMLElement->__construct('') {main} 抛出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>';
?>
请帮我解决这个问题...
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in Stack trace: C:\xampp\htdocs\trendfeeds.php(48): SimpleXMLElement->__construct('') {main} thrown on line 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>';
?>
Please help me on this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试更改
为
看起来空格可能会导致错误
try changing
to
looks like the space might be causing an error