simplexml_load_file - 无法打开流:网络无法访问
simplexml_load_file - failed to open stream: Network is unreachable
我在让我的博客 RSS 提要显示在我的网站上时遇到问题。此代码在本地运行良好,但当我将其上传到服务器时,它会抛出错误。
我得到的错误是:
Warning: simplexml_load_file(http://harrietlawrie.blogspot.com/feeds/posts/default?alt=rss): failed to open stream: Network is unreachable in /srv/disk3/1425834/www/harrietlawrie.co.uk/blog.php on line 47
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://harrietlawrie.blogspot.com/feeds/posts/default?alt=rss" in /srv/disk3/1425834/www/harrietlawrie.co.uk/blog.php on line 47
Warning: Invalid argument supplied for foreach() in /srv/disk3/1425834/www/harrietlawrie.co.uk/blog.php on line 51
我的 PHP 代码是:
<?php
$i = 0; // counter
$url = "http://harrietlawrie.blogspot.com/feeds/posts/default?alt=rss"; // url to parse
$rss = simplexml_load_file($url); // XML parser
// RSS items loop
foreach($rss->channel->item as $item) {
if ($i < 10) { // parse only 10 items
$pubdate = date('D, d M Y H:i:s ', strtotime($item->pubDate));
print '<a href="'.$item->link.'"><h2>'.$item->title.'</h2></a>
<div><b>'. $pubdate.'</b></div>
<br>
<div>'.$item->description.'</div>
<hr>';
}
$i++;
}
?>
我已经在 PHP.ini 中检查了 allow_url_fopen = On
,它就在那里。
有人对我如何解决这个问题有什么建议吗?
谢谢。
我找到了答案。
这是我的虚拟主机的配置问题,我在常见问题解答中找到了这个问题:
- I cannot connect to remote scripts, RSS feeds or use cURL on my website?
The outgoing connections are disabled by default on all accounts for
security reasons, however they can be enabled for paid accounts from
Hosting Settings section. So all you need to do is go to your panel
Hosting Settings section look for "Firewall Options" and click on the
"Enable" button.
来源:FreeHostingEu - http://freehostingeu.runhosting.com/faq.html
我在让我的博客 RSS 提要显示在我的网站上时遇到问题。此代码在本地运行良好,但当我将其上传到服务器时,它会抛出错误。
我得到的错误是:
Warning: simplexml_load_file(http://harrietlawrie.blogspot.com/feeds/posts/default?alt=rss): failed to open stream: Network is unreachable in /srv/disk3/1425834/www/harrietlawrie.co.uk/blog.php on line 47
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://harrietlawrie.blogspot.com/feeds/posts/default?alt=rss" in /srv/disk3/1425834/www/harrietlawrie.co.uk/blog.php on line 47
Warning: Invalid argument supplied for foreach() in /srv/disk3/1425834/www/harrietlawrie.co.uk/blog.php on line 51
我的 PHP 代码是:
<?php
$i = 0; // counter
$url = "http://harrietlawrie.blogspot.com/feeds/posts/default?alt=rss"; // url to parse
$rss = simplexml_load_file($url); // XML parser
// RSS items loop
foreach($rss->channel->item as $item) {
if ($i < 10) { // parse only 10 items
$pubdate = date('D, d M Y H:i:s ', strtotime($item->pubDate));
print '<a href="'.$item->link.'"><h2>'.$item->title.'</h2></a>
<div><b>'. $pubdate.'</b></div>
<br>
<div>'.$item->description.'</div>
<hr>';
}
$i++;
}
?>
我已经在 PHP.ini 中检查了 allow_url_fopen = On
,它就在那里。
有人对我如何解决这个问题有什么建议吗?
谢谢。
我找到了答案。
这是我的虚拟主机的配置问题,我在常见问题解答中找到了这个问题:
- I cannot connect to remote scripts, RSS feeds or use cURL on my website?
The outgoing connections are disabled by default on all accounts for security reasons, however they can be enabled for paid accounts from Hosting Settings section. So all you need to do is go to your panel Hosting Settings section look for "Firewall Options" and click on the "Enable" button.
来源:FreeHostingEu - http://freehostingeu.runhosting.com/faq.html