[英]How to store a PHP variable value into an XML file?
这是我的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>
这将满足您的需求,
<?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());
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.