SimplePie::get_item_quantity PHP Method

get_item_quantity() public method

This is well-suited for {@link http://php.net/for for()} loops with {@see \get_item()}
public get_item_quantity ( integer $max ) : integer
$max integer Maximum value to return. 0 for no limit
return integer Number of items in the feed
    public function get_item_quantity($max = 0)
    {
        $max = (int) $max;
        $qty = count($this->get_items());
        if ($max === 0) {
            return $qty;
        } else {
            return $qty > $max ? $max : $qty;
        }
    }

Usage Example

Example #1
0
 public function respond()
 {
     $url = trim($this->matches[1]);
     $index = 0;
     if (isset($this->matches[2])) {
         $index = intval(trim($this->matches[2]));
         $index = $index - 1;
         $index = max(0, $index);
     }
     $error_level = error_reporting();
     error_reporting($error_level ^ E_USER_NOTICE);
     $feed = new \SimplePie();
     if ($this->cacheEnabled()) {
         $feed->set_cache_location($this->config['cache_directory']);
         $feed->set_cache_duration(600);
     }
     $feed->set_feed_url($url);
     $feed->init();
     $feed->handle_content_type();
     if ($index > $feed->get_item_quantity() - 1) {
         $index = $feed->get_item_quantity() - 1;
     }
     $item = $feed->get_item($index);
     $result = null;
     if ($item) {
         $title = html_entity_decode($item->get_title());
         $link = $item->get_permalink();
         $date = $item->get_date();
         $i = $index + 1;
         $result = "[{$i}] {$date} - {$title} - {$link}";
     }
     error_reporting($error_level);
     return $result;
 }
All Usage Examples Of SimplePie::get_item_quantity