Jump to content
Xisto Corporation

Xml Load() Problem Validating the length of array.

Recommended Posts

Can't seem to figure out this small problem, so I thought I'd send it out to kS to see what I'm not thinking of.


Here are the steps I have taken thus far:

Created an RSS feed

Designed a multipurpose feed reader that will pull data from the RSS feed

Using load() and getElementsByTagName("item") to pull in the data

Part of the reader's parameters are the number of rows to display

There's only one problem...when there are no results to display, it comes up with an error. The simple solution should be to either determine if the first value for the array exists or is blank. Either way, I can't seem to get the array correct no matter how much I try. I've attempted count() and sizeof(), but both return "1", and the error only arises after I try to read from the array using the getElementsByTagName(), so both are a "big help".


Maybe it's late...maybe I'm not thinking straight. Whatever the case, I needed to get connected with you guys again since the shoutbox (or its replacement) is not back online yet.


I'm pasting the code and error below:

2	$rssFile = new DOMDocument();3	$rssFile->load("./rss/?id=" . $feedID);45	//get and output "<item>" elements6	$item=$rssFile->getElementsByTagName("item");7	$y=0;8	if($feedCount>count($item)+1) $feedCount = count($item)+1;9	if(isset($item->item(0)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue))10		{11		for ($i=$feedStart-1; $i<=$feedCount-1; $i++)12			{15			$item_title=$item->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;16			$item_link=$item->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;17			$item_desc=$item->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;

Fatal error: Cannot use object of type DOMNodeList as array in C:\wamp\www\jl-ectronics\resources\php\feedreader01.php  on line 9

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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

Terms of Use | Privacy Policy | Guidelines | 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.