Jump to content
xisto Community
Jonnyabc

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • 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.