My PHP hosting does not support fopen(); necessary to read the RSS XML file. Is there any other way to include an RSS feed into your site without using fopen(); ?
If they support fsockopen(), you can do this: "www.serverwithfeed.com" will need to be set to the host and "/feedurl.rss" to the URL. $handle = fsockopen('www.serverwithfeed.com', 80, $errno, $errstr, 30); fwrite ($handle, "GET /feedurl.rss HTTP/1.1\r\nHost: $host\r\nConnection: Close\r\n\r\n"); while (!feof ($handle)) { $string = fgetc ($handle); if ($string == '<') break; } while (!feof($handle)) { $string .= fread($handle, 40960); } fclose($handle); return $string; PHP:
I'm trying that method you just mentioned, it seems to display a blank page. Below is just an example i'm trying to work with. It shows a blank page when I open the page that handles the PHP code. <?php $handle = fsockopen('www.craigslist.org', 80, $errno, $errstr, 30); fwrite ($handle, "GET http://www.craigslist.org/cpg/index.rss HTTP/1.1\r\nHost: $host\r\nConnection: Close\r\n\r\n"); while (!feof ($handle)) { $string = fgetc ($handle); if ($string == '<') break; } while (!feof($handle)) { $string .= fread($handle, 40960); } fclose($handle); return $string; ?> PHP:
take out the "http://www.craigslist.org" string out of the fwrite line. Also, instead of return $string on the last line, it should be echo $string; (sorry, my bad).
The php script seems to only return the raw XML feed. This is the php test page. This is the script I'm working with: <?php $handle = fsockopen('www.craigslist.org', 80, $errno, $errstr, 30); fwrite ($handle, "GET /cpg/index.rss HTTP/1.1\r\nHost: $host\r\nConnection: Close\r\n\r\n"); while (!feof ($handle)) { $string = fgetc ($handle); if ($string == '<') break; } while (!feof($handle)) { $string .= fread($handle, 40960); } fclose($handle); echo $string; ?> PHP:
Right... that's all it's supposed to do. That will get you the feed (what your host is blocking by not allowing use of URLs in fopen(). Parsing the XML or whatever else you are going to need to do on your own (or find something to do it).
if you are allwoed to use shell_exec() simply do shell_exec("wget www.site.com/feed.xml"); then you would execute $content = shell_exec("cat feed.xml"); all data would be in $content now. then shell_exec("rm -rf feed.xml");