<?xml version="1.0" encoding="UTF-8"?>
<template>
<title>测试</title>
<image>test.jpg</image>
<intro>测试内容</intro>
</template>
<?php
$dir='xml/'; //文件夹下的所有文件
function readxml($dir,&$arr){
if($handle=opendir($dir)){
while(false!==($file=readdir($handle))){
$sub_dir=$dir.DIRECTORY_SEPARATOR.$file;
if(is_dir($sub_dir)&&$file!='.'&&$file!='..'){
readxml($sub_dir,$arr);
}elseif(preg_match('/\.xml$/',$file)){
$arr[]=$sub_dir;
}
}
}
}
readxml($dir,$arr);
foreach($arr as $x){
$doc = new DOMDocument();
$doc->load ($x);
$tmp = $doc->getElementsByTagName('template');
foreach($tmp as $t){
echo $sub_dir;
echo '<td>标题:</td>'.$t->getElementsByTagName('title')->item(0)->nodeValue."<br>";
echo '图片:'.$t->getElementsByTagName('image')->item(0)->nodeValue."<br>";
echo '测试内容:'.$t->getElementsByTagName('intro')->item(0)->nodeValue."<br>";
}
Echo "<hr/>";
}
?>