开发者

How to get the value of an element that it is in a higher level of where your xPath is inside your existing foreach loop [duplicate]

开发者 https://www.devze.com 2023-03-18 08:40 出处:网络
This question already ha开发者_C百科s answers here: Access an element's parent with PHP's SimpleXML?
This question already ha开发者_C百科s answers here: Access an element's parent with PHP's SimpleXML? (3 answers) Closed 9 years ago.

I am creating a PHP script that gets many RSS and displays them on the page sorted by date. My problem is that I need to show the name of the blog and the link to it but they are in a higher level in the structure (as below) of where I get the post's title, link, content, images etc.

My question is how can I easily add the blog's title and link without using a strpos maybe in the link of the post to get the info ?

the rss structure

<rss><chanell><title><link><other info for the blog><item>here goes the elements of the post</item><item>and so on</item>

and the main piece of the code

foreach ($feeds as $feed) {
$xml = simplexml_load_file($feed);
$entries = array_merge($entries, $xml->xpath('/rss/channel//item'));
}
.
.
.
foreach ($entries as $entry) {
echo "the title of the blog and the link"
echo $entry->title; //this is the title of the item
}


Access an element's parent with PHP's SimpleXML?

0

精彩评论

暂无评论...
验证码 换一张
取 消