<?php
//Ricevo le variabili dal form
$post_url=$_POST['url'];
$post_link=$_POST['link'];
$post_info=$_POST['info'];
//Carico il file da modificare
$xml_file = simplexml_load_file("portfolio.xml");
//Creo i nuovi nodi
$work = $xml_file->addChild('work');
$work->addAttribute('url','provaprovaprova');
$url = $work->addChild('url',$post_url);
$link = $work->addChild('link',$post_link);
$info = $work->addChild('info', $post_info);
$dom = new DomDocument();
$newXmlText = $xml_file->asXML();
$dom->loadXML($newXmlText); // same new xmlText as above
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true; // here is where the magic happens
$formatedXML = $dom->saveXML();
//Aggiorno il file
$file = fopen("portfolio.xml","w+");
fwrite($file, $formatedXML);
fclose($file);
?>