1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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 :)

    Code (Text):
    1.  
    2.         $url= $this->get_template_vars('myurl');
    3.  
    4.         $feed = file_get_contents($url);
    5.  
    6.         if ($feed <> false) {
    7.             $rss = new SimpleXmlElement($feed);  
    8.             $i = 0;  
    9.             foreach($rss->channel->item as $entry) {
    10.                 if ($i >=3) {
    11.                     break;
    12.                 } else {
    13.                     echo "<div class='HomepageArticlesWrapper'><p><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></p>";
    14.                     echo "<p>" . $entry->description . "</p></div>";
    15.                     $i += 1;    
    16.                 }
    17.             }
    18.         }
    19.  
    20.  

    Solved! View solution.
    Nima, Nov 17, 2013 IP
  2. CoreyPeerFly

    CoreyPeerFly Well-Known Member Affiliate Manager

    Messages:
    386
    Likes Received:
    21
    Best Answers:
    5
    Trophy Points:
    190
    #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 Premium Member

    Messages:
    3,465
    Likes Received:
    234
    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:

    Code (Text):
    1.  
    2.         {assign var="myurl" value=$smarty.const.SITE_RSS}
    3.     {php}
    4.  
    5.         $url= $this->get_template_vars('myurl');
    6.  
    7.         $feed = file_get_contents($url);
    8.  
    9.         if ($feed <> false) {
    10.             $rss = new SimpleXmlElement($feed);  
    11.             $i = 0;  
    12.             foreach($rss->channel->item as $entry) {
    13.                 if ($i >=3) {
    14.                     break;
    15.                 } else {
    16.                     echo "<div class='HomepageArticlesWrapper'><p><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></p>";
    17.                     echo "<p>" . $entry->description . "</p></div>";
    18.                     $i += 1;    
    19.                 }
    20.             }
    21.         }
    22.  
    23.  
    24.     {/php}
    25.  
    Nima, Nov 17, 2013 IP
  4. CoreyPeerFly

    CoreyPeerFly Well-Known Member Affiliate Manager

    Messages:
    386
    Likes Received:
    21
    Best Answers:
    5
    Trophy Points:
    190
    #4
    CoreyPeerFly, Nov 17, 2013 IP
  5. Nima

    Nima Well-Known Member Premium Member

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

    Code (Text):
    1.  
    2. 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
    3.  
    4. 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
    5. Notice: Undefined index: PRACTICE in/usr/home/path... on line 51
    6.  
    Nima, Nov 17, 2013 IP
  6. #6
    CoreyPeerFly, Nov 17, 2013 IP
  7. Nima

    Nima Well-Known Member Premium Member

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