PHP读取xml方法介绍
http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2012/0110/9638.html
二,php读取xml的方法
xml源文件(尖括号编码了)
<!--?xml version="1.0 encoding="UTF-8"?-->
[humans]
[zhangying]
[name]张映[/name]
[sex]男[/sex]
[old]28[/old]
[/zhangying]
[tank]
[name]tank[/name]
[sex]男[/sex]
[old]28[/old]
[/tank]
[/humans]
1)DOMDocument读取xml
<!--?php
$doc = new DOMDocument();
$doc->load(''person.xml''); //读取xml文件
$humans = $doc->getElementsByTagName( "humans" ); //取得humans标签的对象数组
foreach( $humans as $human )
{
$names = $human->getElementsByTagName( "name" ); //取得name的标签的对象数组
$name = $names->item(0)->nodeValue; //取得node中的值,如
$sexs = $human->getElementsByTagName( "sex" );
$sex = $sexs->item(0)->nodeValue;
$olds = $human->getElementsByTagName( "old" );
$old = $olds->item(0)->nodeValue;
echo "$name - $sex - $old\n";
}
?>