Home > Backend Development > PHP Tutorial > php对xml进行简单的增删改查(CRUD)操作

php对xml进行简单的增删改查(CRUD)操作

WBOY
Release: 2016-06-23 13:50:51
Original
901 people have browsed it

假如有下面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>
Copy after login

如何使用php对它进行CRUD?其实像这种简单的xml文件使用SimpleXMl再好不过了。你可以像这样来操作它:

// 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');
Copy after login

更多详情请移步至PHP官方 usage examples  和  API description .

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template