[英]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.