Page 1 of 1

Printing a filename without .txt

Posted: Wed Sep 25, 2002 1:30 pm
by conthox
Hello

I've got a problem,.

I have this script, it list .txt files in a folder and print it:

Code: Select all

if ($handle = opendir(".")) 
   { 
    while (false !== ($file = readdir($handle))) 
   {
   if (substr($file,-4)==".txt") echo "$file<br>"; 
   &#125; 
   closedir($handle); 
&#125;
How do I do to print the filename without the .txt ?

Posted: Wed Sep 25, 2002 1:38 pm
by volka
the simplest, 'nothing to worry about" way is to use http://www.php.net/manual/en/function.pathinfo.php

Since you already know the extension is '.txt' and 4 characters long you may also use
echo substr($file,0,-4), '<br>';

Posted: Wed Sep 25, 2002 1:48 pm
by conthox
Thank you very much

Hmm,. So simple, but sometimes so difficult to figure out,... :oops:

But here is another one:

How do I sort the output, for exaple by date of upload, or a part of the filename?

Posted: Wed Sep 25, 2002 2:10 pm
by volka

Posted: Wed Sep 25, 2002 2:15 pm
by conthox
Vielen dank!
(Thanks!)