Jump to content

Archived

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

Clandestinex337

creating RSS feed, need help with some things

Recommended Posts

ok so I am working on an RSS feed, but I have some questions on some things that I am not sure how to go about it.

 

right now I have

 

function getRSS($rss_url)
{
$content = file_get_contents($rss_url);
$xml = new SimpleXmlElement($content);

foreach($xml->channel->item as $entry)
{
	echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></br>";
}
}

 

This displays the RSS from a URL, but I want to be able use a form to post the link which will go to a text file.

 

This is the function I have for making the links go to the text file

 

function createRSS()
{
$filename = "rss.txt";
$text = $_POST['rssURL'];
$fp = fopen($filename, "a+");

if (!$fp) 
{
	echo ('File was not written');
} else {
	fwrite ($fp, $text."\n");
	fclose ($fp);

	echo 'File written </br>';
}
}

 

With this function, it creates the text file and inputs w/e I put in the text field, but I want to be able to retrieve each link separately to be able to display the RSS, and I want to be able to delete an RSS if I want to.

 

Could anyone point me into the right direction?

 

Thanks!

Share this post


Link to post
Share on other sites

can i ask why you want to store the url you post into a text file.... are u planning on storing multiple urls in the text file??

Share this post


Link to post
Share on other sites

Im not 100% sure what you are trying to do here, but if the RSS urls are stored in a text file and each url is on a seperate line, you could do this:

 

<?php
$rss_urls = file('rss.txt');
foreach ($rss_urls as $url) {
    getRSS($url);
}
?>

Share this post


Link to post
Share on other sites

Yes I want to store multiple RSS urls in a txt file and be able to display the RSS feed from the txt file and be able to delete the urls from the text file in any order.

Share this post


Link to post
Share on other sites

Here is some more to get you started.

 

<?php
function getRSS($rss_url)
{
 echo '<h1>' . $rss_url . '</h1>';
   $content = file_get_contents(trim($rss_url));
 if ($content) {
   $xml = new SimpleXmlElement($content);
   foreach($xml->item as $entry)
   {
      echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></br>";
   }
 }
}

function createRSS($url)
{
   $filename = "rss.txt";
   $fp = fopen($filename, "a+");
   
   if (!$fp)
   {
      echo ('File was not written');
   } else {
      fwrite ($fp, $url."\n");
      fclose ($fp);
      
      echo 'File written </br>';
   }
}

if ($_POST['action'] == 'Add URL') {
createRSS($_POST['url']);
}


$rss_urls = file('rss.txt');


foreach ($rss_urls as $url) {
getRSS($url);
}

?>
<form method="post" action="">
<input type="text" name="url" /><br />
<input type="submit" name="action" value="Add URL" />
</form>

Share this post


Link to post
Share on other sites

Hmm, I have the following code working on my server (http://losingallhope.com/rss/):

 

<?php
function getRSS($rss_url) {
echo '<h1>' . $rss_url . '</h1>';
$content = file_get_contents(trim($rss_url));
if ($content) {
	$xml = new SimpleXmlElement($content);
	if (count($xml->channel->item)) {
		foreach($xml->channel->item as $entry) {
			echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></br>";
		}
	} else if (count($xml->item)) {
		foreach($xml->item as $entry) {
			echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></br>";
		}
	}
}
}

function createRSS($url) {
   $filename = "rss.txt";
   $fp = fopen($filename, "a+");
   
   if (!$fp) {
      echo ('File was not written');
   } else {
      fwrite ($fp, $url."\n");
      fclose ($fp);
      
      echo 'File written </br>';
   }
}

if ($_POST['action'] == 'Add URL') {
createRSS($_POST['url']);
}

$rss_urls = file('rss.txt');
foreach ($rss_urls as $url) {
getRSS($url);
}

?>
<form method="post" action="">
<input type="text" name="url" /><br />
<input type="submit" name="action" value="Add URL" />
</form>

 

As far as removing urls from the text file, im going to leave that exercise for you. ;)

 

This kind of thing is best left to a database anywayz.

Share this post


Link to post
Share on other sites

 

As far as removing urls from the text file, im going to leave that exercise for you. ;)

 

This kind of thing is best left to a database anywayz.

 

Thanks for the help, the script isn't the most user friendly. I've found out it will only work with http://FEEDURL

 

but most feed links are feed://FEEDURL

 

Thank for all the help. I appreciate it.

Share this post


Link to post
Share on other sites

×

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.