anthonyp01 Posted May 17, 2008 Share Posted May 17, 2008 Hello guys! This is my first post and hopefully you can help me! I am trying to embed my blog into my website and the following code works below on a tempory server but when i run it on my paid server is get this error Warning: Invalid argument supplied for foreach() in Can anybody please help me. <?php $rss = new lastRSS; $rss->cache_dir = "_includes/rsscache/"; $rss->cache_time = 7200; $rssout = $rss->get("http://myaccount.blogspot.com/feeds/posts/default?alt=rss"); foreach($rssout['items'] as $item){ $time = strtotime($item['pubDate']); ?> <h3><?php echo $item['title'];?></h3> <div> <?php echo html_entity_decode($item['description']);?></div> <h6><?php echo date("jS F Y",$time);?></h6> <?php } ?> <?php Many thanks for your help in advance. Anthony Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/ Share on other sites More sharing options...
ShimmyShine Posted May 17, 2008 Share Posted May 17, 2008 I have never had to use foreach but possibly change $rssout['items'] as $item to $rssout['items'] == $item Shimmy Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543530 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 No that doesn't work, thanks for your input though! Anybody else got any clues? :'( Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543535 Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Before the foreach, add: print_r($rssout); And show me the output. Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543538 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Hi Darkwarter, I added that line as you requested but when running the page i get nothing, Just the same error. I added the line here: <?php $rss = new lastRSS; $rss->cache_dir = "_includes/rsscache/"; $rss->cache_time = 7200; $rssout = $rss->get("http://myaccount.blogspot.com/feeds/posts/default?alt=rss"); print_r($rssout); foreach($rssout['items'] as $item){ $time = strtotime($item['pubDate']); ?> <h3><?php echo $item['title'];?></h3> <div> <?php echo html_entity_decode($item['description']);?></div> <h6><?php echo date("jS F Y",$time);?></h6> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543548 Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Print_R didn't output ANYTHING? Not even Array() or something? Check RIGHT before the warning on the output and tell me if you see anything. Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543552 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Nope, Sorry but i'm not that great at php Im a graphic designer and flash programmer mainly. This code worked on another server with no problems, just not on mine. here is my test site im running it on blog is at the bottom http://www.door15.co.uk/HTML/ Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543556 Share on other sites More sharing options...
BlueSkyIS Posted May 17, 2008 Share Posted May 17, 2008 apparently, lastRSS is not installed on the server. the fix might be as simple as including this file: http://lastrss.oslab.net/lastRSS.phps Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543593 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Thank you, where would i put this file? Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543600 Share on other sites More sharing options...
BlueSkyIS Posted May 17, 2008 Share Posted May 17, 2008 i would put it in the same directory as your script, but change the extension from .phps to .php. then change the top of your code like so: <?php include("lastRSS.php"); $rss = new lastRSS; $rss->cache_dir = "_includes/rsscache/"; i assume the directory "_includes/rsscache/" exists and is writable. if not, you'll probably need it. Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543604 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Bah! It gets worse! check this out: http://door15.co.uk/HTML/ Why is doing that? I added your line like this: <?php include("_includes/lastRSS.php"); $rss = new lastRSS; $rss->cache_dir = "_includes/rsscache/"; $rss->cache_time = 7200; $rssout = $rss->get("http://door15design.blogspot.com/feeds/posts/default?alt=rss"); print_r($rssout); foreach($rssout['items'] as $item){ $time = strtotime($item['pubDate']); ?> <h3><?php echo $item['title'];?></h3> <div> <?php echo html_entity_decode($item['description']);?></div> <h6><?php echo date("jS F Y",$time);?></h6> <?php } ?> Are you sure i need lastRSS.php? I have already added this to my file <?php require("_includes/rss.php"); ?> Does that not do the same thing? Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543611 Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Rename it to .php, not .phps. Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543613 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Hi Darkwarter, i have already renamed it to .php Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543615 Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Can we see the line you use to include it? Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543616 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Yes ofc. This is the code for the blog: <?php include("_includes/lastRSS.php"); $rss = new lastRSS; $rss->cache_dir = "_includes/rsscache/"; $rss->cache_time = 7200; $rssout = $rss->get("http://door15design.blogspot.com/feeds/posts/default?alt=rss"); print_r($rssout); foreach($rssout['items'] as $item){ $time = strtotime($item['pubDate']); ?> <h3><?php echo $item['title'];?></h3> <div> <?php echo html_entity_decode($item['description']);?></div> <h6><?php echo date("jS F Y",$time);?></h6> <?php } ?> The include line is at the top. But i have added rss.php at the top of the site: <?php require("_includes/rss.php"); ?> do rss.php and lastRSS.php do similar things? lastRSS.php is not installed on the other server yet the blog runs fine. See here: http://www.clients.interdesigns.co.uk/Door15/ Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543621 Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Considering that we don't know what's in rss.php and lastRss.php, we have NO idea. I'd remove the first include if you don't need it and only use the lastRSS.php include. Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543623 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 So basically this is my problem on the other server: <?php require("_includes/rss.php"); ?> <?php $rss = new lastRSS; $rss->cache_dir = "_includes/rsscache/"; $rss->cache_time = 7200; $rssout = $rss->get("http://door15design.blogspot.com/feeds/posts/default?alt=rss"); print_r($rssout); foreach($rssout['items'] as $item){ $time = strtotime($item['pubDate']); ?> <h3><?php echo $item['title'];?></h3> <div> <?php echo html_entity_decode($item['description']);?></div> <h6><?php echo date("jS F Y",$time);?></h6> <?php } ?> This code works fine on the test server but not on my live server i get this error: Warning: Invalid argument supplied for foreach() in /usr/local/home/httpd/vhtdocs/door15.co.uk/HTML/index.php on line 482 Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543642 Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Did you upload _includes/rss.php along with this file? Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543646 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Yep, this is why i'm pulling my hair out. Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543648 Share on other sites More sharing options...
anthonyp01 Posted May 17, 2008 Author Share Posted May 17, 2008 Could it be the php version on each server? Link to comment https://forums.phpfreaks.com/topic/106059-warning-invalid-argument-supplied-for-foreach-in/#findComment-543652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.