SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Nov 2013
    0 Post(s)
    0 Thread(s)

    Trying to use arrays inside a class

    I am trying to use a class to display an RSS feed. For this example, I am using the BBC RSS feed. The code below is supposed to display first four RSS feed entries:
    PHP Code:
    class Rss_feed
    $title = array();
    $description = array();
       public function 
    __construct($feed_url,$n) {
    $rss simplexml_load_file($feed_url);
    $i 0;
        foreach (
    $rss->channel->item as $feedItem) {
    $this->title[i] = $feedItem->title;
    $this->description[i] = $feedItem->description;
            if (
    $i>=$n) break;

    $BBC_feed = new RSS_feed("",4);

    for (

    "<h2>" $BBC_feed->title[$i] . "</h2>" "<BR>\n";
    $BBC_feed->description[$i] . "\n<BR><BR>";
    However, when I try to display arrays title and description by index, they come out empty in HTML. On the other hand, when parsing the RSS feed directly (via $rss = simplexml_load_file($feed_url); echo $rss->channel->item[0]->title; etc) it works fine. So, the problem is in the way I am handling arrays inside a class, I presume. Could you please point out what is wrong with my code? Thank you.
    Last edited by SpacePhoenix; Nov 5, 2013 at 01:04. Reason: placed php tags around php code

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts