Home >Backend Development >PHP Tutorial >php对xml进行简单的增删改查(CRUD)操作
假如有下面xml文件:
<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>
// CREATE$config = new SimpleXmlElement('<settings></settings>');$config->setting1 = 'setting1 value'; $config->saveXML('config.xml'); // READ$config = new SimpleXmlElement('config.xml');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.xml');