php - check if the file exists, if not, create -


How do I use php dom, if an XML file exists, and it is not created.

   AppendChild ($ newText); $ Xmldoc- & gt; Save ('sample.xml'); ? & Gt;  

Right now, because it does not exist, it gives me this error:

  DOMDocument :: load (): I / O Warning: Failed External To load the unit  

Do not do this with the DOM, check it yourself:

  If (file_exists ('sample.xml')) {$ xmldoc- & gt; Load ('sample.xml'); } And ($ xmldoc-> loadXML ('& lt; root / & gt;'); // or any other Routot name that attacks your fancy}  

file For savings will automatically be $ xmldoc-> Save (); with the next.


Comments

Popular posts from this blog

paypal - How to know the URL referrer in PHP? -

oauth - Facebook OAuth2 Logout does not remove fb_ cookie -

wpf - Line breaks and indenting for the XAML of a saved FlowDocument? -