This is driving me bonkers... I just want to add another img
node.
$xml = <<
DOMDocument::getElementsByTagName doesn't return an array, it returns a DOMNodeList. You need to use the item
method to access its items:
$album = $xmlDoc->getElementsByTagname('album')->item(0);
// Parse error: syntax error, unexpected '[' in /Applications/XAMPP/xamppfiles/htdocs/admin/tests/DOMDoc.php on line 17
you cant do this in php
$album = $xmlDoc->getElementsByTagname('album')[0];
you have to do this
$albumList = $xmlDoc->getElementsByTagname('album');
$album = $albumList[0];
EDIT: getElementsByTagname returns an object so you can do this (above code is incorrect)...
$album = $xmlDoc->getElementsByTagname('album')->item(0);
This error....
// Fatal error: Call to undefined method DOMNodeList::appendChild() in /Applications/XAMPP/xamppfiles/htdocs/admin/tests/DOMDoc.php on line 19
DOMNodeList doesnt have an appendChild method. DOMNode does.