brockelhorst: PHP ->xml

Beitrag lesen

Hallo,
bin leicht übernächtigt, morgen ist deadline... und hänge an einem kleinen Problem.
Ich habe ein php, welches eine xml verändern soll.
die xml sieht so aus:

<?xml version='1.0' encoding='UTF-8'?>
<pictures>
 <image location="bild.jpg" desc="bildbeschreibung" />
 <image location="beispiel.jpg" desc="bildbeschreibung />
</pictures>

es geht jetzt darum ein neu zugefügtes bild in der xml am anfang anzuhängen, jedoch erst nach dem "<?xml version='1.0' encoding='UTF-8'?>"
das php:

//read file
   $contents = fread($handle, filesize($filename));

//rewind file pointer to start and truncate file to zero
   rewind($handle);
   ftruncate($handle, 0);

if ($attach == "start"){
  //attach pictures at beginning of gallery
  $contents = str_replace("<pictures>","",$contents);
  $contents = "<pictures>\n" . $pics_xml_add . $contents;
   } else {
     //attach pictures at end of gally
  $contents = str_replace("</pictures>","",$contents);
  $contents .= $pics_xml_add . "</pictures>";
   }

irgendwie komm ich nicht drauf!? hat jemand rat?