What is wrong with this code

Discussion in 'PHP' started by Nima, Nov 17, 2013.

  1. #1
    Im using this code to publish a feed of our blog's RSS but its not working and I can't figure out why.

    It used to work until a month or so ago (i just realized its not working anymore). I'm thinking it could be because a higher version of php doesn't recognize one of the commands - but i'm not sure. hence why im asking for your help :)

    
            $url= $this->get_template_vars('myurl');
    
            $feed = file_get_contents($url);
    
            if ($feed <> false) {
                $rss = new SimpleXmlElement($feed);   
                $i = 0;   
                foreach($rss->channel->item as $entry) {
                    if ($i >=3) {
                        break;
                    } else {
                        echo "<div class='HomepageArticlesWrapper'><p><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></p>";
                        echo "<p>" . $entry->description . "</p></div>"; 
                        $i += 1;    
                    }
                }
            }
    
    
    Code (markup):
     
    Solved! View solution.
    Nima, Nov 17, 2013 IP
  2. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #2
    Do you have error reporting turned on? I tested your code with a feed and it worked.
     
    CoreyPeerFly, Nov 17, 2013 IP
    Nima likes this.
  3. Nima

    Nima Well-Known Member

    Messages:
    3,489
    Likes Received:
    243
    Best Answers:
    0
    Trophy Points:
    175
    #3
    I dont have error reporting turned on.

    Im using this in a Smarty file so this is the entire code:

    
            {assign var="myurl" value=$smarty.const.SITE_RSS}
        {php}
    
            $url= $this->get_template_vars('myurl');
    
            $feed = file_get_contents($url);
    
            if ($feed <> false) {
                $rss = new SimpleXmlElement($feed);   
                $i = 0;   
                foreach($rss->channel->item as $entry) {
                    if ($i >=3) {
                        break;
                    } else {
                        echo "<div class='HomepageArticlesWrapper'><p><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></p>";
                        echo "<p>" . $entry->description . "</p></div>"; 
                        $i += 1;    
                    }
                }
            }
    
    
        {/php}
    
    Code (markup):
     
    Nima, Nov 17, 2013 IP
  4. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #4
    I recommend turning on error_reporting and see what error it shows you.
     
    CoreyPeerFly, Nov 17, 2013 IP
  5. Nima

    Nima Well-Known Member

    Messages:
    3,489
    Likes Received:
    243
    Best Answers:
    0
    Trophy Points:
    175
    #5
    This is what i get

    
    Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in/usr/home/path... on line 39
    
    Warning: file_get_contents(http://feeds.feedburner.com/Feed) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in/usr/home/path... on line 39
    Notice: Undefined index: PRACTICE in/usr/home/path... on line 51
    
    Code (markup):
     
    Nima, Nov 17, 2013 IP
  6. #6
    CoreyPeerFly, Nov 17, 2013 IP
  7. Nima

    Nima Well-Known Member

    Messages:
    3,489
    Likes Received:
    243
    Best Answers:
    0
    Trophy Points:
    175
    #7
    Thanks. Sent them a message
     
    Nima, Nov 17, 2013 IP