我正在尝试获取RSS源的帖子链接。我正确地加载了一个数组中的所有帖子(我成功地回显了内容和其他标签)但是我有一个问题来获取链接。
在Feed中,可以通过两种方式找到链接
1
<link rel="alternate" type="text/html" href="this is the address I want" title="here goes the title" />
并尝试<?php echo $post->link[href]; ?>
,但由于内容中有很多链接标记,因此必须回显rel="alternate"
2
<feedburner:origLink>this is the address</feedburner:origLink>
并尝试了<?php echo $post->feedburner:origLink; ?>
我的问题是如何获得链接?我更喜欢第二种方式,因为它没有通过feedburner链接。
注意:我在数组中使用了两个RSS XML结构,所以我将使用的是这样的
($post->description)?$post->description:$post->content)
和我的描述/内容一样
答案 0 :(得分:1)
<强> 1。 rel=alternate
强>
$links = $post->xpath('link[@rel="alternate" and @type="text/html"]');
$link = (string) $links[0]['href'];
请参阅http://php.net/simplexmlelement.xpath和http://php.net/simplexml.examples-basic(示例#5)
<强> 2。 feedburner:origLink
强>
$links = $post->xpath('feedburner:origLink');
$link = (string) $links[0];
// or
$link = (string) $post->children('feedburner', TRUE)->origLink;
答案 1 :(得分:0)
我遇到了同样的问题,但我用以下方法解决了这个问题:
$link = $xml->entry[$i]->link[2]->attributes()->href;
//the feed-blog has 3 type of links
您可能$xml
$post
。