Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP从多个文件夹中提取特定的.txt数据并创建一个表_Php_Directory_Extract_Names - Fatal编程技术网

PHP从多个文件夹中提取特定的.txt数据并创建一个表

PHP从多个文件夹中提取特定的.txt数据并创建一个表,php,directory,extract,names,Php,Directory,Extract,Names,我有一个项目,我绝对没有能力。我通常会得到一堆文件夹,里面大约有17个文件。每个文件都有不同的变量,我需要提取并创建一个表。例如: FOLDER: Server 01 TEXT FILE: password parameters.txt PARAMETER: Password Length - 8 PARAMETER: Password Age - 120 days PARAMETER: Password Complexity - enabled TEXT FILE: audit setting

我有一个项目,我绝对没有能力。我通常会得到一堆文件夹,里面大约有17个文件。每个文件都有不同的变量,我需要提取并创建一个表。例如:

FOLDER: Server 01
TEXT FILE: password parameters.txt
PARAMETER: Password Length - 8
PARAMETER: Password Age - 120 days
PARAMETER: Password Complexity - enabled
TEXT FILE: audit settings.txt
PARAMETER: Auditing function 01 - on
PARAMETER: Auditing function 02 - disabled
PARAMETER: Auditing function 03 - enabled

FOLDER: Server 02
TEXT FILE: password parameters.txt
PARAMETER: Password Length - 8
PARAMETER: Password Age - 120 days
PARAMETER: Password Complexity - enabled
TEXT FILE: audit settings.txt
PARAMETER: Auditing function 01 - on
PARAMETER: Auditing function 02 - disabled
PARAMETER: Auditing function 03 - enabled
所有.txt文件名始终相同,变量名始终相同。我只想把“-”后面的内容去掉。我需要创建一个表,其中第一行在A1中显示'Server Name',然后是以下行中的参数标题,例如'password length,password age,password complexity,等等。然后在第二行中,A列将是服务器名称,接下来的列将包含我要提取的参数

完成所有研究后,我能够提取文件夹名称,但无法创建具有以下代码的表:

<?php
$path = 'C:\Documents and Settings\KK\Desktop\kk'; // '.' for current
foreach (new DirectoryIterator($path) as $file)
{
    if($file->isDot()) continue;

    if($file->isDir())
    {
        print $file->getFilename() . '<br />';
    }
}
?>

然后我终于找到了创建表的方法,它将所有子文件夹名称以及文件夹中的所有附加文件都拉入表中。我只是想,如果没有解决这个问题,那么在试图从子文件夹中提取其他文件时,脚本将变得混乱。这是我如何到达那里的

<?php 
// open this directory 
$myDirectory = opendir("C:\Documents and Settings\KK\Desktop\kk");
// get each entry
while($entryName = readdir($myDirectory)) {
    $dirArray[] = $entryName;
}
// close directory
closedir($myDirectory);
//  count elements in array
$indexCount = count($dirArray);
Print ("$indexCount files<br>\n");
// sort 'em
sort($dirArray);
// print 'em
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>Server Name</TH><th>Other Info 01</th><th>Other Info 02</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
        if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
        print("<TR><TD>$dirArray[$index]</td>");
        print("</TR>\n");
    }
}
print("</TABLE>\n");
?>

您正在运行表之前关闭文件,打印$indexCount时是否得到任何数字?您好Shankar,第一个示例在运行表之前关闭,因为每次我尝试将其作为表运行时,它都会不断告诉我它在查找数组。我不知道该怎么做。