I'd like to make a directory listing where instead of the entire
filename I need it to show the filename minus the extention and get the
value of charname= in the file itself.
I've been told that I had to turn the directory listing into an array
and then use "foreach (array as item)" to go through and open each file
but I've tried several different approaches and I just can't get it to work.
I've been able to make it list the directory in order using this script
but after that I'm lost.
<?
$list = Array();
$handle = opendir('testdi r/.');
while (false !== ($file = readdir($handle ))) {
if ($file != "." && $file != "..") {
$list[] = ($file);
}
}
closedir($handl e);
sort ($list);
reset ($list);
while (list ($key, $val) = each ($list)) {
echo "<a href=test.php?n ame=$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) and then the
second $val which it shows in the list to be the value of the line
charname= in the txt files themselves.
Anybody have an idea what I should do?
Kim Jensen
filename I need it to show the filename minus the extention and get the
value of charname= in the file itself.
I've been told that I had to turn the directory listing into an array
and then use "foreach (array as item)" to go through and open each file
but I've tried several different approaches and I just can't get it to work.
I've been able to make it list the directory in order using this script
but after that I'm lost.
<?
$list = Array();
$handle = opendir('testdi r/.');
while (false !== ($file = readdir($handle ))) {
if ($file != "." && $file != "..") {
$list[] = ($file);
}
}
closedir($handl e);
sort ($list);
reset ($list);
while (list ($key, $val) = each ($list)) {
echo "<a href=test.php?n ame=$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) and then the
second $val which it shows in the list to be the value of the line
charname= in the txt files themselves.
Anybody have an idea what I should do?
Kim Jensen
Comment