PHP - Php Creating An Rss Feed
Hi, I have a small piece of code that creates an RSS feed using a mysql database. The issue is the page itself is blank however if I right click and view source I can see all the feed there. I convert the dat time field into a standard RSS date field. The web address is http://vinovote.com/news/feed.php
My code is as follows Code: [Select] <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> <rss version="2.0"> <channel> <title>Vinovote.com</title> <description>The Latest News And Views From Around The Web</description> <link>http://www.vinovote.com/</link> <copyright>Your copyright information</copyright> <?php require_once('../Connections/connection.php'); mysql_select_db($database_vinovotedb, $vinovotedb); $doGet = mysql_query("SELECT feed_content.feed_content_id, feed_content.feed_id, feed_content.url, feed_content.title, feed_content.content, feed_content.item_time, Date_FORMAT(feed_content.item_time,'%a, %d %b %Y %T') AS pubDate FROM feed_content order by item_time desc LIMIT 50 ", $vinovotedb) or die(mysql_error()); while($result = mysql_fetch_array($doGet)){ ?> <item> <title> <?php echo $result['title']; ?></title> <description> <?php echo $result['content'];?></description> <link><?php echo $result['url'];?></link> <pubDate> <?php echo $result['pubDate']; ?></pubDate> </item> <?php } ?> </channel> </rss> Similar TutorialsExample is: https://twitter.com/statuses/user_timeline/kevinhart4real.xml I have all the relevant information I need that i'd like to go in the field, I just need to know how to dynamically create the file with the content and have it update at specific intervals. Any one have any ideas (with PHP) So far I have come up with this: Code: [Select] $link = mysql_connect('localhost','root',''); mysql_select_db('test',$link); $result = mysql_query('SELECT `nationid`,`ruler`,`nation`, `resource1`, `resource2`, `alliance` FROM `nation`'); $doc = new DomDocument('1.0'); $root = $doc->createElement('nationlist'); $root = $doc->appendChild($root); while($row = mysql_fetch_assoc($result)) { $nation= $doc->createElement('nation'); $nation = $root->appendChild($nation); foreach($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $car->appendChild($child); //add data to the new element $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } } $doc->save("nations.xml"); Now that generates 1 .xml file with all the details returned from my query. (also don't bash me for using mysql, it's a quick test) What I would like to do is create a new file for each record in my table and have only the values in that recorded saved to its respective file. I'm lost on this one. This code works fine in Firefox, but not my IE8. I think it has something to do with the <?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?> line, but i'm not sure. IE says "Internet Explorer cannot display this feed" and "A name contained an invalid character. Line: 7 Character: 701." Any ideas? <?php header('Content-Type: text/xml'); ?> <?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?> <?php include('../vars.php'); ?> <rss version="2.0"> <channel> <title>Newsfeed</title> <description>News and Updates</description> <link>http://www.example.com</link> <language>en-us</language> <?php require_once("../conn.php"); $query = "SELECT * FROM news"; $data = mysqli_query($db, $query); while ($row = mysqli_fetch_array($data)) { echo '<item>'; echo ' <title>' . $row['title'] . ' - ' . substr($row['content'], 0, 32) . '...</title>'; echo ' <link>http://www.example.com/new.php?newsid=' . $row['newsid'] . '</link>'; //echo ' <pubDate>' . $row['date'] . '</pubDate>'; echo ' <description>' . $row['content'] . '</description>'; echo '</item>'; } ?> </channel> </rss> Hi All, I'm trying to incorporate a BBC Sport RSS Feed into my website. The following code will show me the news feeds as text and I can include the url's as text also but want to turn this into a clickable url. How do I do this, I cant work it? please help. $feed_url = "http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/teams/s/shrewsbury/rss.xml"; // Get data from feed file $response = file_get_contents($feed_url); // Insert XML into structure $xml = simplexml_load_string($response); // Browse structure foreach($xml->channel->item as $one_item) echo $one_item->title."<BR>"; Hi I get an error when trying to add a link to my rss feed Code: [Select] <link>http://www.jobjar.co.uk/jobdetails.php?keywords=lon0014&page=1</link>Something to do with the last part of the link because when I remove the page=1 it then works. How can I resolve this? Also, will I have to manually update my xml file for rss feeds or can it be updated automatically? If so how? Thanks I have tried sitemap.org and a few others but have not found anything that will give the results I am after. I have a blog site that has a URL and a Description for the URL and wish to have the description show as the anchor text which is linked to the URL, all data is taken from MySQL. Does anyone have a code that will generate something like this ? I have a php script that saves some data as a .xml document. When I view this in my browser I can subscribe to the feed (I am using firefox). However I asked someone else to see if they could subscribe (they were using IE) but the couldn't. Therefore how can users subscribe to my feed? Will only some be able to subscribe? Thanks for any help. Does anybody have any recommendations for PHP scripts to pull in a Twitter feed? I've tried several but each seem to just give me error messages! I basically just need a PHP alternative so that the tweets can be read by search engines. Thanks. hi i want to add some content to my site using xml rss i have a feed i want to show, and the only thing i can find to show it on my page or widgets but they dont look like i want it to look, so i want to make a php script that reads the xml file and then parses it into my website dont know if this is even possible ... but if its possible, is it also possible to filter the feed on certain keywords? Hello all That forum is my last desperate attemp to do what i want to do. Ok here is the story I want to create a simple rss feed in conjuction with php and mysql. I dont want admin areas ect , i just want when i insert a new listing to my database to be able shown up to my (future) rss subscribers. To be more technically specific i want to show to my surfers updates about 2 tables in my database not all the tables. The example i found so far were about only 1 table, plus i was encounting errors to my script. I would like some ideas, directions if someone is kind enough to help a sad developer Thanks in advance! I'm been searching and can't seem to figure this out. I want to take an RSS feed from a news site and display it on my site. any help? Hi, I am reading a feed with this code foreach ($xml->channel->item as $item) { echo $item->title; echo '<br>'; } and outputs Code: [Select] title 1 title 2 title 3 .... and so on until 10 I wants in reverse order to output last rss feed first like: Code: [Select] title 10 title 9 title 8 .... and so on until 1, how can i do it? i tried with rsort($xml->channel->item) butt getting this error: Quote Warning: rsort() expects parameter 1 to be array, object given in Thanks for help Hi, I've written some code to take information from an SQL database and write it out in the RSS format (Although it doesn't validate). The problem is i'd like the page to have the .rss (or .xml) file extension, I'm not sure if there's any advantages in having this but thought i'd ask. I've got the following code: Code: [Select] <?php header('Content-type: text/xml'); print '<?xml version="1.0"?>'; print '<rss version="2.0">'; print '<channel>'; include("phpfunctions.php"); db_connect(); //select all from users table $select="SELECT title, link, description FROM news"; $result = mysql_query($select) or die(mysql_error()); //If nothing is returned display error no records if (mysql_num_rows($result) < 1) { die("No records"); } //loop through the results and write each as a new item while ($row = mysql_fetch_assoc($result)) { $item_title = $row["title"]; $item_link = $row["link"]; $item_desc = $row["description"]; print '<item>'; print '<title>' . $item_title . '</title>'; print '<link>' . $item_link . '</link>'; print '<description>' . $item_desc . '</description>'; print '</item>'; } print '</channel>'; print '</rss>'; ?> This seems to work fine as i get what i expect and i'm assuming i can do the same to output .xml but is there a way to have it in a proper .rss / .xml file so that an aggregator or someone could read this properly. Cheers, Reece Hello! I'm trying to develop some kind of RSS news aggregator and I want to show only feeds younger than 1day. I figured i could transform RSS pubDate to timestamp (strtotime()), but there are some feeds without timestamp (like: http://izklop.com/xmldata/rsslinks.xml). Is there any other way to do it, so I could find timestamp from those feeds without pubdate? If there isn't any other way, do You think it is ok, to just show last 5 feeds? I hope I made my self clear, and please forgive me for my English hi all, i am trying to just get a couple things from this RSS feed: http://www.sierraavalanchecenter.org/bottomline-rss.php I would like to grab the danger rose image on the left, the text that tells of the Avalanche danger ie... "Avalanche Danger Remains LOW..." and the date. I have tried using a few things like: $html = 'http://www.sierraavalanchecenter.org/bottomline-rss.php';$dom = new DOMDocument;$dom->loadHTML($html);$xpath = new DOMXPath($dom);$res = $xpath->query('//div[@id="dangericon"]');if ($res->item(0) !== NULL) { $test = $res->item(0)->nodeValue;}() ...without any luck. Anyone have some advice for me? thanks! I'm not sure you can do this but i would like to grab the image gif from the rss feed of yahoo weather. For instance http://weather.yahooapis.com/forecastrss?p=77056 I pulled this script from a tutorial online and it works great for displaying the temperature and condition and i realize those values are located within the xml. But i would like to grab the image located between the <description> tags (if you look at the source of the rss feed). I don't know if this is possible or not. Thanks. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Yahoo! Weather API RSS</title> <?php function retrieveYahooWeather($zipCode="92832") { $yahooUrl = "http://weather.yahooapis.com/forecastrss"; $yahooZip = "?p=$zipCode"; $yahooFullUrl = $yahooUrl . $yahooZip; $curlObject = curl_init(); curl_setopt($curlObject,CURLOPT_URL,$yahooFullUrl); curl_setopt($curlObject,CURLOPT_HEADER,false); curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true); $returnYahooWeather = curl_exec($curlObject); curl_close($curlObject); return $returnYahooWeather; } $localZipCode = "77056"; // Houston, Tx $weatherXmlString = retrieveYahooWeather($localZipCode); $weatherXmlObject = new SimpleXMLElement($weatherXmlString); $currentCondition = $weatherXmlObject->xpath("//yweather:condition"); $currentTemperature = $currentCondition[0]["temp"]; $currentDescription = $currentCondition[0]["text"]; ?> </head> <body> <h1>Houston, TX</h1> <ul> <li>Current Temperatu <?=$currentTemperature;?>°F</li> <li>Current Description: <?=$currentDescription;?></li> </ul> </body> </html> I'm creating an RSS feed that can be read through an Android app. I've pulled in RSS feeds from CNN and other places and they all seem to have the same setup. They have Title1|||Description1|||Link1 Title2|||Description2|||Link2 ect. How do I create the 3 | (Shift + Backslash) and not have them show up in the feed when viewed through a browser? It's been a while since I've done PHP and I don't remember doing anything like this. Hello, I got myself a RSS feed for my posts, which can be seen he codexplained.tk/feed/rss.php This is the code used for it: Code: [Select] <?php // header header("Content-Type: application/xml; charset=UTF-8"); require("../widgets/functions.php"); // Make a MySQL Connection connectToDB(); echo ' <rss version="2.0"> <channel> <title>Codexplained RSS Feed</title> <link>http://www.codexplained.tk</link> <description>For all your coding needs</description> <language>en</language> '; $query = "SELECT * FROM posts ORDER BY Id DESC LIMIT 15"; $res = mysql_query($query); $num=mysql_numrows($res); $i = 0; while ($i < $num) { $subject=mysql_result($res,$i,"Subject"); $id=mysql_result($res,$i,"Id"); $content=mysql_result($res,$i,"Content"); $content = str_replace("<br />", "\n", $content); $content = str_replace("<?php", "<?php", $content); $content = str_replace("?>", "?>", $content); $content = htmlentities($content); $content = substr($content, 0,400); echo ' <item> <title>'.$subject.'</title> <link>http://www.codexplained.tk/index.php?postDetails='.$id.'</link> <description>'.$content.'</description> </item>'; $i++; } echo ' </channel> </rss> '; ?> Now, I wish to know how to make the time display correctly, and not just according to refresh date. I tried something with <pubDate> but I couldn't figure it out. Help would be appreciated! Hey everyone,
Calling all web devs, so here is my problem from the gecko. I am currently using a free flux theme. The problem is that it has a rss feed news box. I have phpbb forums and i used the link and it wont show. I'm not sure why i did alot of research and it seems it happens because my forums use a php based feed. I do not know how to merge it with the default rsslib.php file that is already there or how to even begin to edit it so it displays correctly on the page. Below is the theme I'm currently using along with a screenshot of the coding for the rsslib.php.
Theme used - Free Flux Green Theme
Screenshots The index.php importing the rsslib.php coding Spoiler |