Jump to content

Recommended Posts

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... 
Link to comment
https://forums.phpfreaks.com/topic/293189-need-input-to-resolve-this-please/
Share on other sites

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]->title
without 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();

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.