似乎当我在“/var/www/cal/attach/”目录中有多个文件时,它只会一遍又一遍地从第一个文件中提取元素。我是否需要以某种方式清除这些元素才能使其正常工作?我想要做的是让脚本遍历多个 *.htm 文件,并将文件中的数据解析为 $value[x] ,稍后我可以调用。然而,多个文件显示相同的值......出了什么问题?
<?php
error_reporting(0);
$today = date("Y-m-d");
foreach (glob("/var/www/cal/attach/*.htm") as $filename) {
$file = $DOCUMENT_ROOT. "$filename";
$doc = new DOMDocument();
$doc->loadHTMLFile($file);
$elements = $doc->getElementsByTagName('td');
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
$value[] = $node->nodeValue. "\n";
}
}
}
echo "date,test,response time,availability,$filename\n";
echo $today . "," . trim($value[25]) . "," . trim($value[26]) . "," . trim($value[27]) . "\n";
echo $today . "," . trim($value[31]) . "," . trim($value[32]) . "," . trim($value[33]) . "\n";
echo $today . "," . trim($value[37]) . "," . trim($value[38]) . "," . trim($value[39]) . "\n";
}
?>