If you have the following XML file:
<span style= "Font-family:simsun;" ><?xml version= "1.0" encoding= "UTF-8"?><setting> <setting1>setting1 value</setting1 > <setting2>setting2 value</setting2> <setting3>setting3 value</setting3> .... .... ....</setting></span>
How do I use PHP to crud it? In fact, it's better to use simplexml like this simple XML file. You can manipulate it like this:
Create$config = new SimpleXMLElement (' <settings/> '), $config->setting1 = ' setting1 value '; $config->savexml (' config + '); Read$config = new SimpleXMLElement (' config: '), echo $config->setting1;echo $config->asxml ();//update$ config->setting1 = ' new value '; $config->setting2 = ' setting2 value '; echo $config->asxml ();//Deleteunset ($ CONFIG->SETTING1); $config->setting2 = Null;echo $config->asxml (); unlink (' config + ');
For more details, please go to PHP official usage examplesand theAPI description.
PHP Simple Delete-and-modify (CRUD) operations on XML