1

以下 PHP 已经工作了几年:

<?php
    $counter = 0;
    $rss = new SimpleXMLElement('http://groups.google.com/group/boy-scout-troop-845/feed/rss_v2_0_msgs.xml', null, true);
?>

它现在产生如下错误:

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ... parser error : Opening and ending tag mismatch: meta line 1 and head in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ..."></head in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ...
: parser error : Opening and ending tag mismatch: head line 1 and html in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ... in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ...  parser error : Premature end of data in tag html line 1 in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: forum/feed/boy-scout-troop-845/msgs/rss_v2_0.xml</a>...</noscript></body></html> in /home/content/t/r/o/troo9757/html/index.php on line 119

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/content/t/r/o/troo9757/html/index.php on line 119

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/content/t/r/o/troo9757/html/index.php:119 Stack trace: #0 /home/content/t/r/o/troo9757/html/index.php(119): SimpleXMLElement->__construct('... on line 119

请注意,我已将链接替换为“...”以使其被接受。我查看了返回的 XML,它看起来很好。有没有可能只是时间太长了?这里有什么建议吗?

谢谢!

4

1 回答 1

0

看起来 Google 已更改其 RSS 提要以将 HTTP 流量重定向到 HTTPS。如果您查看您尝试获取的 XML 文件的响应,它实际上会返回带有重定向标签的 HTML。

只需直接调用 https 即可解决此问题。

$rss = new SimpleXMLElement('https://groups.google.com/group/boy-scout-troop-845/feed/rss_v2_0_msgs.xml', null, true);
于 2013-07-28T15:45:27.653 回答