php輸出xml屬性的方法
更新時間:2015年03月19日 17:01:37 作者:work24
這篇文章主要介紹了php輸出xml屬性的方法,實例分析了php操作XML文件attributes方法的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php輸出xml屬性的方法。分享給大家供大家參考。具體分析如下:
這段代碼通過一個簡單的范例演示了php如何讀取xml文件并輸出xml屬性
<?php
$xml = simplexml_load_file("books.xml");
foreach($xml->book[0]->author->attributes() AS $a => $b) {
echo "$a = $b <br />";
}
?>
xml 文件內容如下
<library> <book> <title>A</title> <author gender="female">B</author> <description>C</description> </book> <book> <title>C</title> <author gender="male">D</author> <description>E</description> </book> <book> <title>F</title> <author gender="male">G</author> <description>H</description> </book> </library>
希望本文所述對大家的php程序設計有所幫助。
相關文章
PHP 字符串正則替換函數(shù)preg_replace使用說明
PHP 字符串正則替換函數(shù)preg_replace使用說明,需要的朋友可以參考下。2011-07-07
PHP foreach遍歷多維數(shù)組實現(xiàn)方式
這篇文章主要為大家詳細介紹了PHP foreach遍歷多維數(shù)組實現(xiàn)方式,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11

