我試圖讓所有的XML文件在我的10個子文件夾,並解析這些文件。要做到這一點,我有以下代碼:PHP越來越子目錄
public static function calculateEAXML ($dir) {
$dh = opendir($dir);
$folderNames = array();
$arr = array();
while (false !== ($folderName = readdir($dh))) {
if ($folderName[0] == "." || (substr($folderName, -3) == "zip")) {continue;}
$folderNames[] = $folderName;
$dom = new DOMDocument;
$dom->validateOnParse = true;
foreach ($folderNames as $file)
{
if(is_dir($folderName)){ScanFiles::calculateEAXML($dir);}
else{
$df = opendir($dir . $file);
while (false !== ($file = readdir($df)))
{
if ($file == "." || $file == ".." ) {continue;}
$dom->Load($dir . $folderName . "/" . $file);
$arr[] = XML2Array::createArray($dom);
}
}
}
return $arr;
}
}
的事情是它只能在一個目錄完全忽視了其他解析文件。有沒有任何想法如何讓它解析所有目錄中的所有文件?
也許這將幫助:http://stackoverflow.com/a/1860417/5440709 – Kanti