I believe you just need to escape the / to get it to work with preg_match...
$regExp = '/^([[:alnum:]_][[:alnum:]_\-]*\/?)*?([[:alnum:]_]+[[:alnum:]_\-]*\.php)?$/i';
echo preg_match($regExp, $fileName);
Also, you will see that I edited my previous post; I believe you are using the regular expression I posted originally, which will match dir/.php; the updated version will not.
Quote:
Originally Posted by grimpirate
What exactly is it the '?' character does? The PHP documentation's description of it doesn't make sense to me.
|
The ? makes the preceding token optional; when it follows a *, it makes the matching engine lazy (as opposed to greedy) with regard to the preceding token. See
here.