Jump to content

php question


systomic26

Recommended Posts

Hey all I got this script:

 

$x = new SimpleXmlElement($content);

 

foreach($x->channel->item as $entry) { 

    echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>"; 

 

This should take an rss xml feed and save the title with a link to the original post as $entry. The problem is that instead of the foreach() function I need a function or a different way to do this that will just take the first item on the list.

 

Please help this is driving me nuts.

Link to comment
Share on other sites

If you mean the second child, then use:

<?php
$x = new SimpleXmlElement($content);
$children = $x->children();
$entry = $children[1]; // Child[1] is the second element.
echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>";  
?>

 

 

If you mean the first sub-child of the first node, then use:

<?php
$x = new SimpleXmlElement($content);
$level1 = $x->children();
$level2 = $level1->children();
$entry = $level2[0];
echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>";  
?>

 

Link to comment
Share on other sites

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.