使用php在wordpress上获取最新的博客文章?

使用php在wordpress上获取最新的博客文章?,php,feed,domdocument,Php,Feed,Domdocument,我使用此php获取我博客的最新帖子: function read_rss($display=0,$url='') { $doc = new DOMDocument(); $doc->load($url); $itemArr = array(); foreach ($doc->getElementsByTagName('item') as $node) { if ($display == 0) { break;

我使用此php获取我博客的最新帖子:

function read_rss($display=0,$url='') {
    $doc = new DOMDocument();
    $doc->load($url);
    $itemArr = array();

    foreach ($doc->getElementsByTagName('item') as $node) {
        if ($display == 0) {
            break;
        }

        $itemRSS = array (
            'title'       => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            'link'        => $node->getElementsByTagName('link')->item(0)->nodeValue,
        );

         array_push($itemArr, $itemRSS);

        $display--;
    }
    return $itemArr;
}
我从一个教程中学到这一点,因为我不知道如何完成这项任务。但它仍然有效,但我一直在错误日志中打印此错误:

[12-Jun-2010 06:13:36] PHP Warning:  DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: Document is empty in http://www.prettyklicks.com/blog/?feed=rss2, line: 1 in public_html/includes/functions.php on line 153
[12-Jun-2010 06:13:36] PHP Warning:  DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: Start tag expected, '&lt;' not found in http://www.prettyklicks.com/blog/?feed=rss2, line: 1 in public_html/includes/functions.php on line 153
[12-Jun-2010 06:13:36]PHP警告:DOMDocument::load()[]:文档在中为空http://www.prettyklicks.com/blog/?feed=rss2,第153行的public_html/includes/functions.php中的第1行
[12-Jun-2010 06:13:36]PHP警告:在中找不到DOMDocument::load()[]:应为开始标记“”http://www.prettyklicks.com/blog/?feed=rss2,第153行的public_html/includes/functions.php中的第1行
有什么想法吗


谢谢

我也遇到了同样的问题,下面是解决方案:

更换线路:

$doc->load($url)


$doc->loadXML(预替换)("/>\s+第16行的
public_html/portfolio.php和第79行的
public_html/includes/functions.php上有什么内容?很抱歉,这实际上与错误无关,我已经编辑了!原始问题您的建议是正确的,只是您的代码需要稍微调整。您在preg_replace和de中缺少一个参数这是你的模式。但谢谢你,效果很好!