這篇文章主要介紹使用php怎么將數(shù)組轉(zhuǎn)化成xml,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
專(zhuān)業(yè)從事做網(wǎng)站、網(wǎng)站建設(shè),高端網(wǎng)站制作設(shè)計(jì),成都小程序開(kāi)發(fā),網(wǎng)站推廣的成都做網(wǎng)站的公司。優(yōu)秀技術(shù)團(tuán)隊(duì)竭力真誠(chéng)服務(wù),采用html5+CSS3前端渲染技術(shù),成都響應(yīng)式網(wǎng)站建設(shè)公司,讓網(wǎng)站在手機(jī)、平板、PC、微信下都能呈現(xiàn)。建站過(guò)程建立專(zhuān)項(xiàng)小組,與您實(shí)時(shí)在線(xiàn)互動(dòng),隨時(shí)提供解決方案,暢聊想法和感受。
使用php將數(shù)組轉(zhuǎn)化成xml的方法:【class Array_to_Xml{private $version = '1.0';private $encoding = 'UTF-8';private $root = 'ro...】。
本文操作環(huán)境:windows10系統(tǒng)、php 7、thinkpad t480電腦。
下面是使用php將數(shù)組轉(zhuǎn)化為xml的具體實(shí)現(xiàn)代碼,一起來(lái)看下吧。
具體實(shí)現(xiàn)代碼:
<?php class Array_to_Xml { private $version = '1.0'; private $encoding = 'UTF-8'; private $root = 'root'; private $xml = null; function __construct() { $this->xml = new XmlWriter(); } function toXml($data, $eIsArray=FALSE) { if(!$eIsArray) { $this->xml->openMemory(); $this->xml->startDocument($this->version, $this->encoding); $this->xml->startElement($this->root); } foreach($data as $key => $value) { if(is_array($value)) { $this->xml->startElement($key); $this->toXml($value, TRUE); $this->xml->endElement(); continue; } $this->xml->writeElement($key, $value); } if(!$eIsArray) { $this->xml->endElement(); return $this->xml->outputMemory(true); } } } $res = array( 'hello' => '11212', 'world' => '232323', 'array' => array( 'test' => 'test', 'b' => array('c'=>'c', 'd'=>'d') ), 'a' => 'haha' ); header("Content-type:text/xml");//輸出xml頭信息 $xml = new Array_to_Xml();//實(shí)例化類(lèi) echo $xml->toXml($res);//轉(zhuǎn)為數(shù)組 ?>
看下運(yùn)行的效果:
以上是“使用php怎么將數(shù)組轉(zhuǎn)化成xml”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前名稱(chēng):使用php怎么將數(shù)組轉(zhuǎn)化成xml
本文來(lái)源:http://jinyejixie.com/article4/ghooie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、企業(yè)建站、App開(kāi)發(fā)、網(wǎng)站營(yíng)銷(xiāo)、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)