Jump to content

Recommended Posts

Hi, Could someone maybe point out how I would do this?

 

I'm trying to display the article:uid from the following XML string:

 

<item>
<title><![CDATA[Headline here]]></title>
<link>http://www.ext_site.com/page/Headlines/0,,12306~1347132,00.html</link>
<pubDate>
Sat, 19 Jul 2008 10:50:00 +0100
</pubDate>
<description><![CDATA[Description goes here]]></description>

<article:uid>1347132</article:uid>

</item>

 

 

I'm using:

<?php
foreach ($xml->xpath('//item') as $item) {

$title = $item->title;
$description = $item->description;
$guid = $item->xpath('//article:uid');

echo "<a href='$link'>".$guid." - ".$title."</a><br />".$description."<br />";
}
?>

 

.. but the guid isn't displaying, it's only saying "Array" - can anyone help me on how to extract the 'article:uid' from the string?

 

All help appreciated,

Thanks - WoolyG

Link to comment
https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/
Share on other sites

Hey, thanks for that.

That works from one instance of <item>, but if I place more than one <item> instance into the XML, then the <article:uid> from the first <item> instance is echoed throughout the page, effectively giving:

 

 

1347132 - Headline here (Item 1)

1347132 - Second Headline (Item 2)

 

.. and I'd like each UID to relate to the <item> it's contained inside.. do you get me?

 

Thanks for your input thus far, any ideas?

WoolyG

try this..

<?php
foreach ($xml->xpath('//item') as $K => $item) {

$title = $item->title;
$description = $item->description;
$guid = $item->xpath('//article:uid');

echo "<a href='$link'>".$guid[$K]." - ".$title."</a><br />".$description."<br />";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.