php數(shù)組格式:
創(chuàng)新互聯(lián)建站-成都網(wǎng)站建設(shè)公司,專注成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、網(wǎng)站營(yíng)銷推廣,域名注冊(cè),網(wǎng)頁空間,網(wǎng)站托管運(yùn)營(yíng)有關(guān)企業(yè)網(wǎng)站制作方案、改版、費(fèi)用等問題,請(qǐng)聯(lián)系創(chuàng)新互聯(lián)建站。
Array to XML:
通過使用PHP的擴(kuò)展SimpleXML,我們將uses_array轉(zhuǎn)換為xml格式。
保存成功的XML文件:
The users.xml file contains the following xml.
附注:
Insert XML Into Databse
If you want to save the XML into the database, then replace the $xml_file variable line with the following code line. Now you can insert $xml_file variable into the database.
php數(shù)組轉(zhuǎn)換xml有好幾種方法,這里演示最簡(jiǎn)單的一種:拼接xml格式數(shù)據(jù)。如果是多維數(shù)組需要另行處理,但套路基本一致。示例如下:
//測(cè)試
$arr=array(
"name"="百度",
"url"="zhidao"
);
echo?arrayToXml($arr);
/*轉(zhuǎn)換結(jié)果
*??xml?version="1.0"?encoding="utf-8"?
*?????name百度/name
*?????urlzhidao/url
*?/xml
*/
//array?轉(zhuǎn)換成xml格式函數(shù)
function?arrayToXml($arr){
$xml?=?"?xml?version=\"1.0\"?encoding=\"utf-8\"?";
foreach?($arr?as?$key=$val){
$xml.="".$key."".$val."/".$key."";
}
$xml.="/xml";
return?$xml;
}
public function arrayToXml($arr){
$xml = "xml";
foreach ($arr as $key=$val){
if(is_array($val)){
$xml.="".$key."".arrayToXml($val)."/".$key."";
}else{
if (is_numeric($val)){
$xml.="".$key."".$val."/".$key."";
}else{
$xml.="".$key."![CDATA[".$val."]]/".$key."";
}
}
}
$xml.="/xml";
return $xml;
}
分享題目:多維php轉(zhuǎn)換xml數(shù)據(jù) php生成xml
文章來源:http://jinyejixie.com/article16/hpdpgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、、外貿(mào)建站、域名注冊(cè)、Google、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)