0

Forgive me because my knowledge of PHP is limited but I have this code which retrieves all the items from an RSS Feed but I now need it to be using a for loop instead of a foreach loop so that I can limit the amount of times it runs and what item number it starts from. How would I go about doing this? Thank you for your help in advance.

$urls = array("WordlideVideo" => "http://feeds.reuters.com/reuters/USVideoWorldNews");

$rss = fetch_rss($urls[$_GET['url']]);

foreach ($rss->items as $item) {
    $href  = $item['link'];
    $title = $item['title'];
    $video = $item['video'];
    $titleLength = strlen($title);

if ($titleLength > 180) {
    $title = substr($title, 0, 177);
    $title = $title . "...";
} else { 
    $title = $title;
}

}
1
  • I am using the magpie api Commented Apr 20, 2015 at 18:07

1 Answer 1

1

Assuming $rss->items is an array, you should be able to do something like the following:

$items = $rss->items;
$limit = count($items);

// put any logic here to reduce $limit if it's greater than your threshold

for($i=0; $i<$limit; $i++) {
    $item = $items[$i];

    // code as before inside foreach loop
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.