0

私のウェブサイトには、次のコードを含むテーブルがあります。

<table width="100%" id="tabloadwar" cellspacing="1" cellpadding="0" border="0">
<?php

$subdirs = array_map('intval', scandir("/war"));
$max = max($subdirs);

for($i=1;$i<=max;$i++){ ?>
<tr>
<td width="15%"><?php echo $i; ?></td>
<td width="85%">
<?php $percorso = file("dir1/content.txt"); $line = file($percorso); echo $line?></td></tr>

<?php } ?>
</table>

上記のコードを使用して、サーバー内のディレクトリ数と同じ数の行を持つテーブルを作成したいと考えています。ちなみに、テーブル内に何も表示されないため、機能していません。行の例はこれです

<tr>
<td width="15%">1</td> // i value
<td width="85%">Italy</td> //text on the 1st line of my *.txt file
</tr>

また、その代わりに、nameというファイルの内容を入れなければなりませんdir1/content.txt。まだ何も見えないので、それも機能していません。何か助けはありますか?

4

1 に答える 1

0

ここ$maxではなく黙想する必要がありますmaxfor($i=1;$i<=max;$i++){

このコードを試して、何が起こるか見てください..

<?php
  if ( !file_exists( "/war" ) ) {
    echo "'/war' not exists<br />";
  }
  if ( !file_exists( "dir1/content.txt" ) ) {
    echo "'content.txt' not exists<br />";
  }
?>
<table width="100%" id="tabloadwar" cellspacing="1" cellpadding="0" border="0">
<?php
  $subdirs  = array_map( "intval", scandir( "/war" ) );
  $max  = max( $subdirs );

  for( $i = 1; $i <= $max; $i++ ) {
?>
  <tr>
    <td width="15%"><?php echo $i; ?></td>
    <td width="85%">
    <?php
      $lines  = file( "dir1/content.txt" );
      echo implode( "<br />", $lines );
    ?>
    </td>
  </tr>

<?php
  }
?>
</table>

フォルダー内のサブフォルダーの数を取得したい....rows as the count of directories in my server...
場合はglobGLOB_ONLYDIRフラグで使用できます

<?php
  $dirs = glob( "path/to/dir/*", GLOB_ONLYDIR );
  $total_dirs = count( $dirs );
?>
于 2013-07-19T12:52:56.377 に答える