这篇文章主要介绍了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如何输出xml属性”这篇文章对大家有帮助,同时也希望大家多多支持天达云,关注天达云行业资讯频道,更多相关知识等着你来学习!