PHP 如何向xml中追加写入
发布网友
发布时间:2022-04-22 07:52
我来回答
共1个回答
热心网友
时间:2022-04-22 09:21
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());