PHP 如何向xml中追加写入 10
如题,怎么在原本的XML后面增加新的信息<?xmlversion="1.0"encoding="utf-8"?><vip><user><email>test@163.co...
如题,怎么在原本的XML后面增加新的信息
<?xml version="1.0" encoding="utf-8"?>
<vip>
<user>
<email>test@163.com</email>
<time>2016-05-31</time>
<ip>127.0.0.1</ip>
<user>
</vip>
===========================================
想做到自动在后面一直追加,例如
<vip>
<user>
<email>test@163.com</email>
<time>2016-05-31</time>
<ip>127.0.0.1</ip>
<user>
<user>
<email>追加1</email>
<time>追加1</time>
<ip>追加1</ip>
<user>
<user>
<email>追加2</email>
<time>追加2</time>
<ip>追加2</ip>
<user>
</vip>
麻烦告之具体怎么写,小白,跪谢! 展开
<?xml version="1.0" encoding="utf-8"?>
<vip>
<user>
<email>test@163.com</email>
<time>2016-05-31</time>
<ip>127.0.0.1</ip>
<user>
</vip>
===========================================
想做到自动在后面一直追加,例如
<vip>
<user>
<email>test@163.com</email>
<time>2016-05-31</time>
<ip>127.0.0.1</ip>
<user>
<user>
<email>追加1</email>
<time>追加1</time>
<ip>追加1</ip>
<user>
<user>
<email>追加2</email>
<time>追加2</time>
<ip>追加2</ip>
<user>
</vip>
麻烦告之具体怎么写,小白,跪谢! 展开
1个回答
2016-05-31
展开全部
1.xml:
<?xml version="1.0" encoding="utf-8"?>
<vip>
<user>
<email></email>
<time>2016-05-31</time>
<ip>127.0.0.1</ip>
</user>
</vip>
php:
<?php
$xmlstr = file_get_contents('1.xml');
$users = new SimpleXMLElement($xmlstr);
$user = $users->addChild('user');
$user->addChild('email', 'test');
$user->addChild('time', 'test');
$user->addChild('ip', '127.0.0.1');
$users->asXML();
file_put_contents('1.xml', $users->asXML());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询