0

I m working on a website which extracts news feed from my blog to the website. It workd fine in my localhost but when the content is online, the same code does not work. Here are my code.

    <?php
$i = 0; // counter
$j=0;
$des="";
$url = "http://lampsoftnepal.com/?feed=rss2"; // url to parse
$rss = simplexml_load_file($url); // XML parser
$dater=array();
$mylink=array();
$mytitle=array();
// RSS items loop

print '<h2><img style="vertical-align: middle;" src="'.$rss->channel->image->url.'" /> '.$rss->channel->title.'</h2>'; // channel title + img with src

foreach($rss->channel->item as $item) {
if ($i < 8) { // parse only 10 items
    //print $item->pubDate;
    $mylink[$i]=$item->link;
    $mytitle[$i]=$item->title;
    $dater[$i]=$item->pubDate;
    }



$i++;
}
print '<a href="'.$item->link[0].'" target="_blank">'.$item->title[1].'</a><br />';

//print $dater[1];


?>

Here is the code where i want to print the date

<div class="list-group"> 

            <div class="media list-group-item">


                  <a class="pull-left" href="news-events.html">
                    <img class="media-object" src="images/stree2.jpeg" alt="...">
                  </a>
                  <div class="media-body">
                      <a href="news-events.html">

                        <h4 class="list-group-item-heading">Somae's Story <span class="news-date"><?php echo $dater[0]; ?></span></h4>
                        <p class="list-group-item-text">Lorem ipsum doner mata coma, orem ipsum doner mata coma, Lorem ipsum.</p>
                      </a>
                </div><!-- end of media-body -->
            </div><!-- end of media list-group-item -->

        </div><!-- end of list-group -->

        </div><!-- end of side-box -->
     </div>

1 Answers1

0

Your code is working for me as well. Seems like SimpleXML is not enabled in your host. Please check like below by creating a sample page.

  <?php
   echo phpinfo();
  ?>

You can see SimpleXML enabled or disabled, Or try below code.

<?php
if (function_exists('simplexml_load_file')) {
    echo "simplexml_load_file function exists!<br />\n";
} else {
    echo "simplexml_load_file function doesn't!.<br />\n";
}
?>
Jenson M John
  • 5,499
  • 5
  • 30
  • 46
  • Thank you for your answer, and yes my SimpleXML is enabled!!!!Actually it works fine in my local host but does not work on my server!!! – user2550011 Nov 02 '14 at 10:07
  • Whether you checked in your server? Can you show screenshot URL of phpinfo in your server? – Jenson M John Nov 02 '14 at 10:17
  • No, i dont have enough point to upload a photo!!but this is my test url u can chek here http://hariyalihost.com/check.php.. – user2550011 Nov 02 '14 at 11:51