PHP simplexml_load_string()函數(shù)實(shí)例講解
PHP simplexml_load_string() 函數(shù)
實(shí)例
轉(zhuǎn)換形式良好的 XML 字符串為 SimpleXMLElement 對(duì)象,然后輸出對(duì)象的鍵和元素:
<?php $note=<<<XML <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> XML; $xml=simplexml_load_string($note); print_r($xml); ?>
定義和用法
simplexml_load_string()
函數(shù)轉(zhuǎn)換形式良好的 XML 字符串為 SimpleXMLElement 對(duì)象。
語法
simplexml_load_string( _data,classname,options,ns,is_prefix_ );
實(shí)例 1
輸出 XML 字符串中每個(gè)元素的數(shù)據(jù):
<?php $note=<<<XML <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> XML; $xml=simplexml_load_string($note); echo $xml->to . "<br>"; echo $xml->from . "<br>"; echo $xml->heading . "<br>"; echo $xml->body; ?>
實(shí)例 2
輸出 XML 字符串中每個(gè)子節(jié)點(diǎn)的元素名稱和數(shù)據(jù):
<?php $note=<<<XML <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> XML; $xml=simplexml_load_string($note); echo $xml->getName() . "<br>"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br>"; } ?>
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
相關(guān)文章
通過對(duì)服務(wù)器端特性的配置加強(qiáng)php的安全
通過對(duì)服務(wù)器端特性的配置加強(qiáng)php的安全...2006-10-10弄了個(gè)檢測(cè)傳輸?shù)膮?shù)是否為數(shù)字的Function
弄了個(gè)檢測(cè)傳輸?shù)膮?shù)是否為數(shù)字的Function...2006-12-12PHP CURL CURLOPT參數(shù)說明(curl_setopt)
這篇文章主要介紹了PHP CURL CURLOPT參數(shù),需要的朋友可以參考下2013-09-09