Hi all
I'm sure the solution to this is blindingly obvious but it's late at night and I'm completely stumped at the moment...
Here's my code so far:
$xmlDoc = new DOMDocument();
$xmlDoc->load('file.xml');
$xmlGigs = $xmlDoc->getElementsByTagName("gig");
$calendar = array(
"date" => array(),
"venue" => array(),
"title" => array(),
"bands" => array()
);
$totalGigs = $xmlGigs->length;
for ($i=0; $i<$totalGigs; $i++)
{
$calendar['date'][$i] = $xmlGigs->item($i)->getElementsByTagName("when");
}
As you can see, I simply loop through my XML sheet and extract data into the $calendar array using a FOR loop. I want to change the last section to use a FOREACH loop instead and this is what I've changed it too:
$i = 0;
foreach ($xmlGigs as $Gig)
{
$calendar['date'][$i] = $Gig->item($i)->getElementsByTagName("when");
++$i;
}
...and it just won't work!! I'm getting a "Fatal error: Call to undefined method DOMElement::item()" error and I just can't figure out why.
Anyone? 🙂