Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create while loop for feed

Posted on 2011-09-03
3
Medium Priority
?
318 Views
Last Modified: 2012-05-12
So I am pulling in and parsing an rss feed with this script:

<?php
error_reporting(E_ALL);

$xml = file_get_contents('http://feedurlhere');

// MUNG THE XML BECAUSE WE DO NOT HAVE THE NAMESPACE INFORMATION
$xml = str_replace('content:encoded', 'content__encoded', $xml);
$xml = str_replace('isc:',            'isc__',            $xml);

// CONVERT THE XML TO AN OBJECT
$obj = SimpleXML_Load_String($xml, 'SimpleXMLElement', LIBXML_NOCDATA);


// GET SOME FIELDS
$item_title = $obj->channel->item->title;
$item_link = $obj->channel->item->link;
$item_description = $obj->channel->item->description;

echo "$item_image<br/><strong>$item_title</strong> $item_description<br/>";

?>


My question is... Currently this script just returns the variables from the latest entry in the feed. How do I create something like a while loop that returns everything in the feed?
0
Comment
Question by:pixelscape
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 36478875
Try this:

foreach ($obj->channel->item as $element){
  echo "title is " . $element->title . "<br />";
  echo "item_link is " . $element->item_link . "<br />";
  echo "item_description is " . $element->item_description . "<br />"
}

Cheers
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36479126
...everything in the feed?  That might be a lot of stuff.  But marqusG has the iterator correct.  No points for this answer, please.  You might want to think about a usort() and a foreach() construct that gives you access to the last five entries, or something like that.  Best regards, ~Ray
0
 

Author Comment

by:pixelscape
ID: 36482497
Thanks for the input guys, based my script on marqus' foreach suggestion. Works great.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question