jusaf Posted March 9, 2009 Share Posted March 9, 2009 Hi everyone! I am new to PHP (2 days old) so don't go on running out with your hands on your head screaming if you see some absurdity in my code... be gentle please... here is the deal, i did a form that adds some data to a XML file, and it works fine, but the new data is added at the end of the file, but i need the new node to be inserted to the begining so i decided i would just move the newly inserted node (the last one) to the begining and move all other one position down. The problem is that the last one actually goes to the first place but all other nodes loses their data... here is the code: //first lets copy the last one to an aux var $aux = clone $xml->titulo[sizeof($xml->titulo) - 1]; //now lets loop through every element and move them down for($i = sizeof($xml->titulo) - 2; $i >= 0 ; $i--){ $xml->titulo[$i + 1] = clone $xml->titulo[$i]; } //now lets put the aux to first place $xml->titulo[0] = clone $aux; the tag i am trying to move is as you can see "titulo" and it contains stuff like "<b>bla bla bla</b> big bla". the $xml var is created using simplexml_load_file. any idea? or if by any chance there is a way to directly add a child node to the begining instead of the end please let me know... anyway, thanks in advance! Julien Link to comment https://forums.phpfreaks.com/topic/148542-solved-simplexml/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.