I have this regex:
'/^files\/(.+\..+)$/';
But I want to replace the "files/" section with a runtime variable.
I tried this:
$filePath = "files/";
'/^'.$filePath.'(.+\..+)$/';
which didn't work, as well as this:
$filePath = preg_quote("files/");
'/^'.$filePath.'(.+\..+)$/';
but I still get an error in this loop on the preg_match line, saying that "(" is an unknown modifier.
foreach (glob(FILE_PATH."*.*") as $filename) {
preg_match($pattern, $filename, $matches);
echo "<option class='file' value='".$matches[1]."'>".$matches[1]."</option>";
}
Any help would be appreciated, thanks.
EDIT
This works...
$filePath = 'files\/';
...but in actual usage, I'm trying to use a constant declared in another file.
So:
define('FILE_PATH', 'files/');
...and then trying to use that constant. It can't have the escape character embedded because some other parts of the application need it without the escape character.
$filePathcontain slashes (/)? That conflicts with the regex delimiters you use. You should always regex-escape content you inject into expressions.preg_quoteis for). he is just missing a parameter ;)