這篇文章主要介紹了php使用simplexml_load_file加載XML文件并顯示XML的方法,實例分析了simplexml_load_file操作XML文件的技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了php使用simplexml_load_file加載XML文件并顯示XML的方法。分享給大家供大家參考。具體實現方法如下:
- <?php
- $xml = simplexml_load_file("sample.xml");
- echo htmlspecialchars($xml->asXML());
- ?>
sample.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程序設計有所幫助。
新聞熱點
疑難解答