Jump to content

creating RSS feed, need help with some things


Clandestinex337

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!

Link to comment
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>

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.