亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP simplexml_load_string()函數(shù)實例講解

 更新時間:2019年02月03日 10:48:28   作者:php參考手冊  
今天小編就為大家分享一篇關(guān)于PHP simplexml_load_string()函數(shù)實例講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

PHP simplexml_load_string() 函數(shù)

實例

轉(zhuǎn)換形式良好的 XML 字符串為 SimpleXMLElement 對象,然后輸出對象的鍵和元素:

<?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 對象。

語法

simplexml_load_string( _data,classname,options,ns,is_prefix_ );

實例 1

輸出 XML 字符串中每個元素的數(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; 
?>

實例 2

輸出 XML 字符串中每個子節(jié)點的元素名稱和數(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é)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

相關(guān)文章

最新評論