XML文件的CRUD节点和节点值的一个简单程序我决定将设置保存在XML文件中,因为字段只有一个值。我的xml文件就像<?xml version="1.0" encoding="UTF-8"?><setting>
<setting1>setting1 value</setting1>
<setting2>setting2 value</setting2>
<setting3>setting3 value</setting3>
....
....
....</setting>有人能建议我一个简单的php脚本来读取、编辑、添加和删除节点和节点值吗?
2 回答
catspeake
TA贡献1111条经验 获得超0个赞
SimpleXML
// CREATE$config = new SimpleXmlElement('<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');
- 2 回答
- 0 关注
- 348 浏览
添加回答
举报
0/150
提交
取消