Author Topic: creating RSS feed, need help with some things  (Read 1241 times)

0 Members and 1 Guest are viewing this topic.

Offline Clandestinex337Topic starter

  • Irregular
  • Posts: 48
    • View Profile
creating RSS feed, need help with some things
« on: November 16, 2008, 10:42:55 AM »
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

Code: [Select]
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

Code: [Select]
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!

Offline Clandestinex337Topic starter

  • Irregular
  • Posts: 48
    • View Profile
Re: creating RSS feed, need help with some things
« Reply #1 on: November 16, 2008, 07:37:45 PM »
anyone? I would really like to know how to do this :(

Thanks

Offline gaza165

  • Enthusiast
  • Posts: 469
  • Gender: Male
    • View Profile
    • Design Monkeys
Re: creating RSS feed, need help with some things
« Reply #2 on: November 16, 2008, 07:46:21 PM »
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??

Offline flyhoney

  • Devotee
  • Posts: 845
  • Gender: Male
    • View Profile
    • blag
Re: creating RSS feed, need help with some things
« Reply #3 on: November 16, 2008, 08:02:12 PM »
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:

Code: [Select]
<?php
$rss_urls 
file('rss.txt');
foreach (
$rss_urls as $url) {
    
getRSS($url);
}
?>

"The enemy's gate is down." - Ender
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors'1);    // the script you are debugging

Offline Clandestinex337Topic starter

  • Irregular
  • Posts: 48
    • View Profile
Re: creating RSS feed, need help with some things
« Reply #4 on: November 17, 2008, 02:20:10 PM »
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.

Offline Clandestinex337Topic starter

  • Irregular
  • Posts: 48
    • View Profile
Re: creating RSS feed, need help with some things
« Reply #5 on: November 18, 2008, 03:41:05 PM »
bump

Offline flyhoney

  • Devotee
  • Posts: 845
  • Gender: Male
    • View Profile
    • blag
Re: creating RSS feed, need help with some things
« Reply #6 on: November 18, 2008, 04:18:27 PM »
Here is some more to get you started.

Code: [Select]
<?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>
« Last Edit: November 18, 2008, 04:19:01 PM by flyhoney »
"The enemy's gate is down." - Ender
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors'1);    // the script you are debugging

Offline Clandestinex337Topic starter

  • Irregular
  • Posts: 48
    • View Profile
Re: creating RSS feed, need help with some things
« Reply #7 on: November 18, 2008, 05:58:27 PM »
that works in posting into and showing the text file, but it doesn't show the RSS Feed if its a feed url. :(

Offline flyhoney

  • Devotee
  • Posts: 845
  • Gender: Male
    • View Profile
    • blag
Re: creating RSS feed, need help with some things
« Reply #8 on: November 18, 2008, 06:59:05 PM »
Hmm, I have the following code working on my server (http://losingallhope.com/rss/):

Code: [Select]
<?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.
« Last Edit: November 18, 2008, 06:59:47 PM by flyhoney »
"The enemy's gate is down." - Ender
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors'1);    // the script you are debugging

Offline Clandestinex337Topic starter

  • Irregular
  • Posts: 48
    • View Profile
Re: creating RSS feed, need help with some things
« Reply #9 on: November 18, 2008, 07:59:10 PM »

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.

Offline Clandestinex337Topic starter

  • Irregular
  • Posts: 48
    • View Profile
Re: creating RSS feed, need help with some things
« Reply #10 on: November 19, 2008, 02:16:29 PM »
any idea?

Offline premiso

  • Karma Chameleon
  • Staff Alumni
  • Freak!
  • *
  • Posts: 6,670
  • Gender: Female
  • effing right
    • View Profile
    • PHP Help
Re: creating RSS feed, need help with some things
« Reply #11 on: November 19, 2008, 02:26:54 PM »
Why not just do a str_replace() and replace feed:// with http://  ??