Miscellaneous > Programming & Networking

I AM ANGERED.

(1/1)

TheQuirk:
Wiggin. What's up with this?

 
quote:<? $maindir = "./" ; $mydir = opendir($maindir) ; $exclude = array("index.php","..",".","*.php"); while($fn = readdir($mydir)) { if ($fn == $exclude[4] || $fn == $exclude[1]) continue; echo "<br><a href='$fn' target=\"_blank\">$fn</a>"; } closedir($mydir); ?>
--- End quote ---


Output:

 
quote:
.
jesus_vs_tool.txt <--What's THIS does here?
K2CKabani.htm
OutAcOntRoLL187.htm
<SNIP>
sys0p.txt
TheComMercials02.htm
index.php  <--What's THIS doing here?

--- End quote ---

voidmain:
Uh, could you be a little more specific? Obviously the first part is a piece of PHP code. I assume the second part is a list of files produced by the PHP code. But I don't understand what you are angry about. Unless you didn't write the code or place the files in question in a place that you control.

TheQuirk:
No, that's all of the code. My problem is that even though I have the "files" ".", "..", and "index.php" in my aray, it still displays ".." and "index.php".

voidmain:
Oh, I get it now. I do this all the time but differently than you are doing it. Also use "code" tags when pasting code into a message. Keeps the format right.

First of all it looks like in your code you *want* to grab a list of files and exclude certain ones. It looks as if you "wish" to exclude "index.php" and all other "*.php" files. If that is the case, the partial answer is to change your subscripts from 1 and 4 to 0 and 3 (the first element of the array is actually 0).

When fixed this will still not exclude the "." and ".." because the "||" symbol means "or" not "through". And the 4th element (*.php) will not expand and match all PHP files, but instead would look for a single PHP file named literally '*.php'. If you'll also notice '..' *was* excluded from your list because exclude[1] is the 2nd element.

I assume that what you *really* want to do is ignore all files in your array right? I usually use the PHP grep function for this.

I'll copy/paste it into a PHP file and straighten it out for you...

[ January 09, 2003: Message edited by: void main ]

voidmain:
Here's the way I would have done it:


--- Code: ---
--- End code ---

And of course wrap your HTML around the echo "$file" statement.

Navigation

[0] Message Index

Go to full version