php - Rss feed not working online -
php - Rss feed not working online -
i m working on website extracts news feed blog website. workd fine in localhost when content online, same code not work. here code.
<?php $i = 0; // counter $j=0; $des=""; $url = "http://lampsoftnepal.com/?feed=rss2"; // url 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 src foreach($rss->channel->item $item) { if ($i < 8) { // parse 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 code want print 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>
your code working me well. seems simplexml not enabled in host. please check below creating sample page.
<?php echo phpinfo(); ?> you can see simplexml enabled or disabled, or seek 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"; } ?> php html rss feedparser
Comments
Post a Comment