note 112913 added to domdocument.save

From: Date: Tue, 06 Aug 2013 09:42:39 +0000
Subject: note 112913 added to domdocument.save
Groups: php.notes 
Request: Send a blank email to php-notes+get-195883@lists.php.net to get a copy of this message
I had been hitting my head against the wall when I couldn't get an edited XML file to save due to file permissions, even though I knew that it was OK. Eventually I realised that for some odd reason, when I went to save the XML file, it would try to write the file to the root directory. As such, use realpath() to keep the complete system path to the XML file when you load it: <?php $myfile = 'myxml.xml'; $myfile = realpath($myfile); $doc = new DOMDocument('1.0'); $doc->load($myfile); // Let's just add a couple of elements for good measure $root = $doc->documentElement; $title = $doc->createElement('title'); $title = $root->appendChild($title); $text = $doc->createTextNode('This is a title'); $text = $title->appendChild($text); $doc->save($myfile); ?> ---- Server IP: 69.147.83.199 Probable Submitter: 31.24.217.72 ---- Manual Page -- http://php.net/manual/en/domdocument.save.php Edit -- https://master.php.net/note/edit/112913 Del: integrated -- https://master.php.net/note/delete/112913/integrated Del: useless -- https://master.php.net/note/delete/112913/useless Del: bad code -- https://master.php.net/note/delete/112913/bad+code Del: spam -- https://master.php.net/note/delete/112913/spam Del: non-english -- https://master.php.net/note/delete/112913/non-english Del: in docs -- https://master.php.net/note/delete/112913/in+docs Del: other reasons-- https://master.php.net/note/delete/112913 Reject -- https://master.php.net/note/reject/112913 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195883) next »