Avatar of pixelscape
pixelscape

asked on 

Create while loop for feed

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?
PHP

Avatar of undefined
Last Comment
pixelscape
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

...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
Avatar of pixelscape
pixelscape

ASKER

Thanks for the input guys, based my script on marqus' foreach suggestion. Works great.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo