Jump to content

Help with this script


systomic26

Recommended Posts

Hey I was wandering if you guys could help me out with this. I'm kind of newbie so be patient please. It's supposed to take the first <item> from the specified rss feed and display it.

 

<?php  

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);

$feed_url = "some feed url";   

function getFeed($feed_url) {  
         
       $content = file_get_contents($feed_url);  
       $x = new SimpleXmlElement(channel->item as $entry);
        
       $children = $x->children();
       $entry = $children[0];
       
        
       echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a><br><br><p>" . $entry->description . "</p>";  
       
       
} 

getFeed($feed_url);

?>  

 

Somebody please help.

Link to comment
https://forums.phpfreaks.com/topic/136258-help-with-this-script/
Share on other sites

function getFeed($feed_url) {  
   $content = file_get_contents($feed_url);  
   $xml = new SimpleXmlElement($content);
   list($entry) = $xml->children();
   printf('<a href="%s" title="%s">%s</a><br><br><p>%s</p>',$entry->link,$entry->title,$entry->title,$entry->description);
}

function getFeed($feed_url) {  
   $content = file_get_contents($feed_url);  
   $xml = new SimpleXmlElement($content);
   list($entry) = $xml->children();
   printf('<a href="%s" title="%s">%s</a><br><br><p>%s</p>',$entry->link,$entry->title,$entry->title,$entry->description);
}

 

That isn't working right. This script is not selecting the first <item> in the xml feed it is selective for the first <title>. This dispays the feed's name and description. I need it to display the first rss post on the list (the data found after the first <item> tag). I appreciate the suggestion though.

I figured it out!!

 

for anyone else that is interested here is the code:

 

<?php  

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);

$feed_url = "some feed url";   

function getFeed($feed_url) {  
   $content = file_get_contents($feed_url);  
   $xml = new SimpleXmlElement($content);
   $lis1 = (string) $xml->channel->item[0]->title;
   $lis2 = (string) $xml->channel->item[0]->description;
   $lis3 = (string) $xml->channel->item[0]->link;
   printf('<a href="%s" title="%s">%s</a><br><br><p>%s</p>',$lis3,$lis1,$lis1,$lis2);
}

getFeed($feed_url);

?>  

 

Thanks for helping me figure this out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.