I have a xml file with many elements, I am looking to remove certain elements based on their indexes.
Sample XML:
<songs>
<song>
<title>A</title>
<artist>AA</artist>
</song>
</song>
PHP Code I have so far:
<?php
$index = $_GET['song'];
$doc = new DOMDocument();
$doc->load("songs.xml");
$songs = $doc->getElementsByTagName("song");
foreach($songs as $song) {
if(in_array( $song[$index], $songs)){
unset($song);
}
}
$doc->save("songlist.xml");
?>
But I get this error from this code:
Fatal error: Cannot use object of type DOMElement as array
Any help at all is appricated in this issue, thank you.
No comments:
Post a Comment