Connecting Tech Pros Worldwide Forums | Help | Site Map

Read rss based news and reviews from other website

Familiar Sight
 
Join Date: Aug 2008
Posts: 175
#1: Jun 12 '09
Hey all,
I want to read news and reviews from a website
http://carsguide.news.com.au/site/rss/

and want to populate on my website. How can i read that rss and show on my website using php

kind regards,
Mohsin Rafique

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#2: Jun 12 '09

re: Read rss based news and reviews from other website


Quote:

Originally Posted by neovantage View Post

How can i read that rss

any XML reader will do (DOMDocument, SimpleXML, …)

Quote:

Originally Posted by neovantage View Post

and show on my website using php

you could use XSLT to make the RSS into HTML directly. or use the XML reader to output the appropriate data.
Familiar Sight
 
Join Date: Aug 2008
Posts: 175
#3: Jun 15 '09

re: Read rss based news and reviews from other website


Hey Sir,
I have found a script which do this all for you and we just needs to pass the RSS URl of the website to whom we want to grab the news.

It's really very nice script.
I want to share this with this great community of experts as may be this will be helpful for those like me.

here is the URL: A PHP script to get the contents of a remote RSS file

Expand|Select|Wrap|Line Numbers
  1. <?
  2. /*
  3. ======================================================================
  4. Get, cache, and output contents of a RSS XML file
  5. Author: George at JavaScriptKit.com/ DynamicDrive.com
  6. Created: Feb 1st, 2006. Updated: Feb 1st, 2006
  7. ======================================================================
  8. */
  9.  
  10. header('Content-type: text/xml');
  11.  
  12. // -------------------------------------------------------------------
  13. // Enter list of possible RSS feeds to fetch inside array:
  14. // -------------------------------------------------------------------
  15.  
  16. $rsslist=array(
  17. "CNN" => "http://rss.cnn.com/rss/cnn_topstories.rss",
  18. "BBC" => "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml",
  19. "news.com" => "http://news.com.com/2547-1_3-0-5.xml",
  20. "slashdot" => "http://rss.slashdot.org/Slashdot/slashdot",
  21. "dynamicdrive" => "http://www.dynamicdrive.com/export.php?type=new"
  22. );
  23.  
  24. $cachefolder="cache"; //path to cache directory. No trailing "/". Set dir permission to read/write!
  25.  
  26. // -------------------------------------------------------------------
  27. // Determine which RSS file to actually fetch
  28. // Based on the value of the "id" parameter of the URL string mapping to the RSS array's key
  29. // -------------------------------------------------------------------
  30.  
  31. $rssid=$_GET['id'];
  32. $rssurl=isset($rsslist[$rssid])? $rsslist[$rssid] : die("Error: Can't find requested RSS in list.");
  33. $localfile=$cachefolder. "/" . urlencode($rssurl); //Name cache file based on RSS URL
  34.  
  35. // -------------------------------------------------------------------
  36. // Get the minutes to cache the local RSS file based on "cachetime" parameter of URL string
  37. // -------------------------------------------------------------------
  38.  
  39. $cacheminutes=(int) $_GET["cachetime"]; //typecast "cachetime" parameter as integer (0 or greater)
  40.  
  41. // -------------------------------------------------------------------
  42. // fetchfeed() gets the contents of an external RSS feed,
  43. // and saves its contents to the "cached" file on the server
  44. // -------------------------------------------------------------------
  45.  
  46. function fetchfeed(){
  47. global $rssurl, $localfile;
  48. $contents=file_get_contents($rssurl); //fetch RSS feed
  49. $fp=fopen($localfile, "w");
  50. fwrite($fp, $contents); //write contents of feed to cache file
  51. fclose($fp);
  52. }
  53.  
  54. // -------------------------------------------------------------------
  55. // outputrsscontent() outputs the contents of a RSS feed using the cached local RSS file
  56. // It checks if a cached version of the RSS feed is available, and if not, creates one first.
  57. // -------------------------------------------------------------------
  58.  
  59. function outputrsscontent(){
  60. global $rssurl, $localfile, $cacheminutes;
  61. if (!file_exists($localfile)){ //if cache file doesn't exist
  62. touch($localfile); //create it
  63. chmod($localfile, 0666);
  64. fetchfeed(); //then populate cache file with contents of RSS feed
  65. }
  66. else if (((time()-filemtime($localfile))/60)>$cacheminutes) //if age of cache file great than cache minutes setting
  67. fetchfeed();
  68. readfile($localfile); //return the contents of the cache file
  69. }
  70.  
  71. outputrsscontent();
  72. ?>
  73.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#4: Jun 15 '09

re: Read rss based news and reviews from other website


so you didn't want to process the RSS file in the first place?

EDIT:
better use $_GLOBAL['name'] than global $name

maybe OOP can improve the code even more.
Familiar Sight
 
Join Date: Aug 2008
Posts: 175
#5: Jun 15 '09

re: Read rss based news and reviews from other website


i don't get you sir.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#6: Jun 15 '09

re: Read rss based news and reviews from other website


I thought you wanted to do anything to the RSS. but looking at the script, it does only fetch the feed, thus my question.
Familiar Sight
 
Join Date: Aug 2008
Posts: 175
#7: Jun 15 '09

re: Read rss based news and reviews from other website


yep that's all i want to do for the time being now Sir
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#8: Jun 15 '09

re: Read rss based news and reviews from other website


then I misunderstood your question. the mentioned techniques are used to process RSS (which obviously includes loading)…
Familiar Sight
 
Join Date: Aug 2008
Posts: 175
#9: Jun 15 '09

re: Read rss based news and reviews from other website


On more question sir i am stuck in Thickbox Image Gallery

I have integrated Thickbox Gallery images for multiple images. So that once a member/client/visitor view the images he/she can navigate easily.

It just do not show any image if i used it's property rel means same rel element and value. It does not work. Can some body view on my script and tell me what is the problem behind this issue.
here is the live demo of the my work

Go to this link
http://www.neovantage.net/projects/carsbay/search.php

Then click on Start Finding button. Once the page will open it show only one record. Click on Dealer Enquiry Link or click on images. it will take to you on the detail page. There you will see the pictures list and here i integrated Thickbox image gallery. when you will click on thumbnail then you will get my problem that it loads nothing just keep on browsing the page n that's it

kindly solve my problem Sir.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#10: Jun 15 '09

re: Read rss based news and reviews from other website


I've alread read that…

please respect the Posting Guidelines and don't hijack your own thread.
Reply