hi all

i have a directory that contains more files:

034.php
second.txt
3_4555.xls
53.doc
521.doc
.....

How can i do read and print only those files that begin with (e.g.) "53"?

    $dir = '/path/to/directory';
    $files = glob($dir . '/53*');
    echo "<pre>".print_r($files, 1)."</pre>";
    

      ok, sounds good.
      But how can i assign the values (file names) to one or more variables?

      i tried this, but it shows only one value:

      echo $files[0];

        $dir = '/path/to/directory';
        $files[] = glob($dir . '/53*');
        

        This way you would get an array of these values in $files array, so you could list them through array listing functions...

          joane1;10877513 wrote:

          ok, sounds good.
          But how can i assign the values (file names) to one or more variables?

          i tried this, but it shows only one value:

          echo $files[0];

          Not sure I follow, but $files will be an array of matches that you can traverse that via a [man]foreach[/man] loop, or use any of the many array functions to further manipulate the array. For instance, if you wanted a list of links:

          <ul class='file_list'>
          <?php
          foreach($files as $file)
          {
             echo "<li><a href='".$file."'>".basename($file)."</a></li>\n";
          }
          ?>
          </ul>
          
            Write a Reply...