Clandestinex337 Posted November 16, 2008 Share Posted November 16, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/ Share on other sites More sharing options...
Clandestinex337 Posted November 17, 2008 Author Share Posted November 17, 2008 anyone? I would really like to know how to do this Thanks Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-691718 Share on other sites More sharing options...
gaza165 Posted November 17, 2008 Share Posted November 17, 2008 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?? Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-691725 Share on other sites More sharing options...
flyhoney Posted November 17, 2008 Share Posted November 17, 2008 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-691737 Share on other sites More sharing options...
Clandestinex337 Posted November 17, 2008 Author Share Posted November 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-692189 Share on other sites More sharing options...
Clandestinex337 Posted November 18, 2008 Author Share Posted November 18, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-692931 Share on other sites More sharing options...
flyhoney Posted November 18, 2008 Share Posted November 18, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-692951 Share on other sites More sharing options...
Clandestinex337 Posted November 18, 2008 Author Share Posted November 18, 2008 that works in posting into and showing the text file, but it doesn't show the RSS Feed if its a feed url. Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-693045 Share on other sites More sharing options...
flyhoney Posted November 18, 2008 Share Posted November 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-693085 Share on other sites More sharing options...
Clandestinex337 Posted November 19, 2008 Author Share Posted November 19, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-693109 Share on other sites More sharing options...
Clandestinex337 Posted November 19, 2008 Author Share Posted November 19, 2008 any idea? Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-693738 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 Why not just do a str_replace and replace feed:// with http:// ?? Quote Link to comment https://forums.phpfreaks.com/topic/132939-creating-rss-feed-need-help-with-some-things/#findComment-693742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.