View Single Post

  #4 (permalink)  
Old 11-16-2004
Erich Musick
 
Posts: n/a
Default Re: Directory listing with file info

This method, though, assumes that all extensions are exactly three
characters long.

What about extensions such as pl, py, h, among others?



Pedro Graca wrote:
> Kim Jensen wrote:
>
>>while (list ($key, $val) = each ($list)) {
>> echo "<a href=test.php?name=$val>$val</a><br>";
>>
>>}
>>
>>Here I'd like the $val after the name= to be just the filename without
>>the extention (all files in the directory are txt files)

>
>
> echo '<a href="test.php?name=', substr($val, -4), ">$val</a><br";
>
>
>>and then the
>>second $val which it shows in the list to be the value of the line
>>charname= in the txt files themselves.

>
>
> Are you really sure you want to do that?
> You have top open each and every file, read/print its contents, and close
> the file. It might be a lot slow!
>
>
> /* needs error-checking for fopen() and fgets() */
> foreach ($list as $val) {
> $f = fopen($val);
> while (!feof(f)) {
> $line = fgets($f);
> if (preg_match('/^charname=(.*)$/', $line, $matches)) {
> echo '<a href="test.php?name=', urlencode(substr($val, -4)),
> '">', $matches[1], '</a><br>';
> break; /* leave inner while() */
> }
> }
> fclose($f);
> }


--
In Christ,

Erich Musick
http://erichmusick.com

In the same way, let your light shine before others, so that they may
see your good works and give glory to your Father who is in heaven. --
Matthew 5:16 NKJV
Reply With Quote