如何將xml和jsonp轉(zhuǎn)換為PHP數(shù)組?相信很多新手小白還沒學(xué)會(huì)這個(gè)技能,通過這篇文章的總結(jié),希望你能學(xué)會(huì)這個(gè)技能。以下資料是實(shí)現(xiàn)的步驟。
成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供煙臺(tái)網(wǎng)站建設(shè)、煙臺(tái)做網(wǎng)站、煙臺(tái)網(wǎng)站設(shè)計(jì)、煙臺(tái)網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、煙臺(tái)企業(yè)網(wǎng)站模板建站服務(wù),十載煙臺(tái)做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
一、xml轉(zhuǎn)成數(shù)組,xml中包含<![CDATA[]]>標(biāo)簽
/** * 將xml轉(zhuǎn)換為數(shù)組 * @param string $xml:xml文件或字符串 * @return array */ function xmlToArray($xml){ //考慮到xml文檔中可能會(huì)包含<![CDATA[]]>標(biāo)簽,第三個(gè)參數(shù)設(shè)置為LIBXML_NOCDATA if (file_exists($xml)) { libxml_disable_entity_loader(false); $xml_string = simplexml_load_file($xml,'SimpleXMLElement', LIBXML_NOCDATA); }else{ libxml_disable_entity_loader(true); $xml_string = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA); } $result = json_decode(json_encode($xml_string),true); return $result; }
二、jsonp轉(zhuǎn)換成數(shù)組
/** * 把jsonp轉(zhuǎn)為php數(shù)組 * @param string $jsonp jsonp字符串 * @param boolean $assoc 當(dāng)該參數(shù)為true時(shí),將返回array而非object * @return array */ function jsonp_decode($jsonp, $assoc = false) { $jsonp = trim($jsonp); if(isset($jsonp[0]) && $jsonp[0] !== '[' && $jsonp[0] !== '{') { $begin = strpos($jsonp, '('); if(false !== $begin) { $end = strrpos($jsonp, ')'); if(false !== $end) { $jsonp = substr($jsonp, $begin + 1, $end - $begin - 1); } } } return json_decode($jsonp, $assoc); }
上文描述的就是將xml和jsonp轉(zhuǎn)換為PHP數(shù)組的方法,具體使用情況還需要大家自己動(dòng)手實(shí)驗(yàn)使用過才能領(lǐng)會(huì)。如果想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前文章:如何將xml和jsonp轉(zhuǎn)換為PHP數(shù)組
網(wǎng)址分享:http://muchs.cn/article4/jpeioe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、電子商務(wù)、App開發(fā)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)