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

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -