这是我的XML文件conf.xml
:
<?xml version="1.0" encoding="ISO-8859-1"?>
<conf>
<auth>
<ids></ids>
<key></key>
</auth>
</conf>
这是我的PHP文件change.php
<?php
$DBUNAME="BOB1";
$DBPWD="BOB2";
?>
我希望变量$DBUNAME
和$DBPWD
作为元素添加到XML文件中
<ids>BOB1</ids>
<key>BOB2</key>
答案 0 :(得分:1)
这将满足您的需求,
<?php
$file ="config.xml";
$DBUNAME="BOB1";
$DBPWD="BOB2";
//load xml object
$xml= simplexml_load_file($file);
//assign auth id
$xml->auth->ids = $DBUNAME;
//assign auth key
$xml->auth->key = $DBPWD;
//store the value into the file
file_put_contents($file, $xml->asXML());
?>