Topic: create xml from filenames

Hi,

how can i create a xml from a form field?
I tried this. But this doesn't work.

// remove extension from files
            $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $fileName);
            
            foreach($withoutExt as $withoutExt_string) { 

            $doc = new DOMDocument('1.0');
            // we want a nice output
            $doc->formatOutput = true;

            $root = $doc->createElement('phpemail');
            $root = $doc->appendChild($root);

            $email = $doc->createElement('email');
            $email = $root->appendChild($email);

            $text = $doc->createTextNode($_POST['email']);
            $text = $email->appendChild($text);

            $doc->save($targetDir . $withoutExt_string . ".xml");
            
            }