不能重复自己的两种类型的文件

时间:2018-05-30 16:12:28

标签: php html glob

我知道我有两个foreach但是当我将一个txt的glob分配给var时它不起作用。它应该为每个html文件找到写对应的txt文件等等,只有一次。我怎么能动摇这个?

<?php

echo '<h2>Escolha o Esquema de MetaDados a utilizar</h2>';
echo '<table cellspacing="0" cellpadding="0" border="0" class="table">';
echo '<tr>';
echo '<th>Esquema de MetaDados</th>';
echo '<th>Descrição</th>';
echo '</tr>';


foreach (glob("Templates/Dinamico/*.html") as $filename) {
    foreach (glob("Templates/Dinamico/*.txt") as $txtname) {
        $fileH = basename($filename, ".html");
        $fileT = basename($txtname, ".txt");
        if ($fileH = $fileT) {
            $txt = file_get_contents($txtname);
            if ($filename != "Templates/Dinamico/formD1.html") {
                echo '<tr>';
                echo '<td>';
                echo "<a strong href='" . $filename . "'>" . $fileH . "</a>";
                echo '</td>';
                echo '<td>';
                echo $txt;
                echo '</td>';
                echo '</tr>';
                //just checking the files
                echo "$filename size " . filesize($filename) . "\n";
            }
        }
    }
}

preview

1 个答案:

答案 0 :(得分:0)

<?php

    echo '<h2>Escolha o Esquema de MetaDados a utilizar</h2>';
    echo '<table cellspacing="0" cellpadding="0" border="0" class="table">';
    echo '<tr>';
    echo '<th>Esquema de MetaDados</th>';
    echo '<th>Descrição</th>';
    echo '</tr>';

          foreach (glob("Templates/Dinamico/*.html") as $filename) {
          foreach(glob("Templates/Dinamico/*.txt") as $txtname){ 
           $fileH= basename($filename,".html");
           $fileT= basename($txtname,".txt");   
          if($fileH==$fileT){ 
          $txt= file_get_contents ( $txtname); 
        if($filename != "Templates/Dinamico/formD1.html"){ 
            echo'<tr>';
            echo'<td>';
            echo "<a name='".$fileH."'strong href='Templates/Dinamico/formD1.php?id=$fileH'>".$fileH."</a>";
            echo'</td>';
            echo'<td>';
            echo $txt;
            echo'</td>';
            echo'</tr>';

}
}
}
}

    ?>