Heim >Backend-Entwicklung >PHP-Tutorial >php动态生成xml

php动态生成xml

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:20:181350Durchsuche

工作遇到这样一个场景,前台用户的配置操作,需要后台php使用XML保存下来。问题是如何用php生成一个XML文件之后,我需要动态的修改用户改过的信息,或者动态添加用户新增的信息。

回复内容:

工作遇到这样一个场景,前台用户的配置操作,需要后台php使用XML保存下来。问题是如何用php生成一个XML文件之后,我需要动态的修改用户改过的信息,或者动态添加用户新增的信息。

用SimpleXML

<code class="php">$x = new SimpleXMLElement("<your_xml_root></your_xml_root>");
$x->a = 1234;
echo $x->asXML();
//<?xml version="1.0"?>
//<your_xml_root><a>1234</a></your_xml_root></code>

asXML(); 方法支持带一个参数,你用来保存文件的文件名
SimpleXMLElement可以由simplexml_load_file函数来进行构造,从文件读取XML直接创建一个SimpleXMLElement对象

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn