cowboysdude Posted December 20, 2014 Share Posted December 20, 2014 Haven't been here in a while but I have stumped myself at the moment or maybe I've looked at it too much LOL This is what I have and it does work but gives me errors on my page... This is my helper.php: function truncText($text, $chars) { if (strlen($text) <= $chars) return $text; $new = wordwrap($text, $chars, "|"); $newtext=explode("|",$new); return $newtext[0]; } function getRSS( $params ) { $doc = new DOMDocument(); $doc->load($params->get( 'feed', 'http://googleblog.blogspot.com/atom.xml' )); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { if ($i >= $params->get('numitems',5)){ break; } $arrFeeds[$i]->title = $node->getElementsByTagName('title')->item(0)->nodeValue; $arrFeeds[$i]->desc = self::truncText($node->getElementsByTagName('description')->item(0)->nodeValue, $params->get( 'desclen', 120)); $arrFeeds[$i]->link = $node->getElementsByTagName('link')->item(0)->nodeValue; $arrFeeds[$i]->pubDate = $node->getElementsByTagName('pubDate')->item(0)->nodeValue; $i++; } return $arrFeeds; } } The error I am getting is this: Notice: Undefined variable: i in helper.php on line 33 Notice: Undefined variable: i in helper.php on line 34 Warning: Creating default object from empty value in helper.php on line 34 Notice: Undefined variable: i in helper.php on line 35 Notice: Undefined variable: i in helper.php on line 36 Notice: Undefined variable: i in helper.php on line 37 Notice: Undefined variable: i in helper.php on line 39 Warning: Creating default object from empty value in helper.php on line 34 Warning: Creating default object from empty value in helper.php on line 34 Warning: Creating default object from empty value in helper.php on line 34 Warning: Creating default object from empty value in helper.php on line 34 So there you have it... not sure how to fix it... Any help is appreciated to show me the errors of my ways... Quote Link to comment https://forums.phpfreaks.com/topic/293189-need-input-to-resolve-this-please/ Share on other sites More sharing options...
requinix Posted December 20, 2014 Share Posted December 20, 2014 You need to define things before you try to use them. You try to use $i without giving it a value anywhere, and you do $arrFeeds[$i]->titlewithout first setting $arrFeeds[$i] to anything. Set $i=0, I assume, before you try to use it, and initialize the values in $arrFeeds with $arrFeeds[$i] = new stdClass(); Quote Link to comment https://forums.phpfreaks.com/topic/293189-need-input-to-resolve-this-please/#findComment-1500136 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.