检索博客文章URL


Retrieve Blogger post URL

我正在尝试使用PHP和XML:从博客中检索帖子

$file="BLOG URL/atom.xml";
$xml = simplexml_load_file($file);

做一个简单的循环:

foreach ($xml->entry as $foo) {
    echo '<h2>' . $foo->title . '</h2>';
    echo '<p>' . $foo->updated . '</p>';
    echo $foo->link;
}

唯一的问题是链接没有显示。

检查代码,每个帖子都有一个以上的链接节点:

<link href="" rel="replies" title="Postar comentários" type="application/atom+xml"/>
<link href="" rel="replies" title="0 Comentários" type="text/html"/>
<link href="" rel="edit" type="application/atom+xml"/>
<link href="" rel="self" type="application/atom+xml"/>
<link href="" rel="alternate" title="" type="text/html"/>

通过他的心房类型可以得到一个结节吗?

您可以通过循环链接并选择一个链接来获得它。所以改变:

foreach ($xml->entry as $foo) {
    echo '<h2>' . $foo->title . '</h2>';
    echo '<p>' . $foo->updated . '</p>';
    echo $foo->link;
}

收件人:

foreach ( $xml->entry as $foo ) {
    echo '<h2>' . $foo->title . '</h2>';
    echo '<p>' . $foo->updated . '</p>';
    foreach ( $foo->link as $link ) {
        $type = (string) $link->attributes()->{'type'};
        if ( $type == 'text/html' ) {
            echo (string) $link->attributes()->{'title'};;
        }
    }
}

其中'text/html'是要选择的类型。