【问题标题】:simplexml_load_file not working to read rss feed at www.thetechjournal.comsimplexml_load_file 无法读取 www.thetechjournal.com 上的 rss 提要
【发布时间】:2013-08-02 00:22:58
【问题描述】:

当我尝试阅读 www.thetechjournal.com 上的 rss 提要时,我什么也得不到。他们使用 wordpress 生成 rss,所以我认为这与此有关。

<?php
$url = 'http://feeds.thetechjournal.com/TheTechJournal';
$rss = simplexml_load_file($url);
print_r($rss);
?>

更新:有问题的 XML 已作为图像附加。

【问题讨论】:

  • 您可以使用此服务来检查提要是否有效(尽管目前它似乎不适合我)validator.w3.org/feed

标签: wordpress rss simplexml


【解决方案1】:

他们的提要有错误。用这个检查它:

$url = 'http://feeds.thetechjournal.com/TheTechJournal';
libxml_use_internal_errors(true);
$sxe = simplexml_load_string($url);
if ($sxe === false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
    echo "\t", $error->message;
}
}
print_r($rss);

【讨论】:

  • 澄清一下,任何形式的 PHP xml 解析都会失败,因为它会返回无效的 CDATA
  • 您好 wunderdojo,感谢您提供代码。当我运行您的代码时,我收到以下错误消息:“无法加载预期的 XML 开始标记,未找到 '
  • 该提要未传递有效的 XML 标记。我只是在处理一些事情之前尝试并清理它,但没有去。这就是我要去的地方: $url = "feeds.thetechjournal.com/TheTechJournal"; $file = file_get_contents($url, FALSE, stream_context_create(array('http' =>array('user_agent' => 'php' )))); $xml=html_entity_decode($file, ENT_COMPAT, 'UTF-8'); $dom = 新的 DOMDocument; $dom->loadXML($xml); echo $dom->saveXml();
  • 无效的 XML 行位于 951 到 954 之间,请参见我刚刚在初始消息中发布的图像。如果我删除这 4 行,则 XML 有效。但我不知道是什么导致了问题。
  • 顺便提一下,您提供的提要错误代码始终返回“加载 XML 开始标记失败,未找到 '
【解决方案2】:

我来自 TTJ 团队。当我运行此验证器时,它显示正常,但由于我们有一些 iFrame 标记了这些问题。有时,如果某些帖子有任何奇怪的字符,那是什么使它无效。请向我指出我们可以调查的任何确切问题。非常感谢您的关注。

http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Ffeeds.thetechjournal.com%2FTheTechJournal

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    相关资源
    最近更新 更多