php輸出xml屬性的方法

字號(hào):


    這篇文章主要介紹了php輸出xml屬性的方法,實(shí)例分析了php操作XML文件attributes方法的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    本文實(shí)例講述了php輸出xml屬性的方法。分享給大家供大家參考。具體分析如下:
    這段代碼通過(guò)一個(gè)簡(jiǎn)單的范例演示了php如何讀取xml文件并輸出xml屬性
    <?php
    $xml = simplexml_load_file("books.xml");
    foreach($xml->book[0]->author->attributes() AS $a => $b) {
    echo "$a = $b <br />";
    }
    ?>
    xml 文件內(nèi)容如下
    <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>
    希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。