PDA

View Full Version : Wildcards in PHP



jmiller
July 15th, 2003, 17:22
I am working on a small script that displays my text, htm, mrc, etc files with a banner ad above.

Part of my script contains the following


<?php include($get.".txt"); ?>

Where the given text file will be retrieved and displayed.
What I was wanting to do was have something similar, but with a wildcard or something, so I can display any file extension.

Any suggestions?

Abush
July 15th, 2003, 17:31
try .* or *.*

jmiller
July 15th, 2003, 17:50
Nope, already tried those.
They don't work.

Cagez
July 15th, 2003, 19:08
I don't think you can do that, the next best thing that I'd do is make an array of the extensions you want to be able to use, something like this


$valid_ext = array('php','txt','inc','html');

foreach($valid_ext as $ext)
{
$file = $get.'.'.$ext;
if(file_exists($file))
{
// if it exists, include it
include($file);
// we've got our file, so we can discontinue the loop
break;
}
}

jmiller
July 15th, 2003, 19:17
Thanks cagez, that is PERFECT!