开发者

Regarding php Regular expression filenames

开发者 https://www.devze.com 2022-12-25 11:51 出处:网络
Edit: (here is a better live example: http://vzio.com/upload/reg_pattern.php) I am very bad at regular expressions, but I have a regular expression that is working okay, except for one issue:

Edit: (here is a better live example:

http://vzio.com/upload/reg_pattern.php)

I am very bad at regular expressions, but I have a regular expression that is working okay, except for one issue:

/\/(.*?).php/
开发者_JS百科

I only need this regular expression to find things like:

/this-a-valid-page.php {some words here} /anotherpage.php { some words here} http://www.google.com

but do not find URLs the problem i am having is that it find this parts of full URLS i want it to avoid these all together. http://www.google.com/page.php because i have another function that does something different than the filename reg exp.


/^\/(.*?)\.php$/

bash:~$ php -a
php > $test = array('pass' => '/test.php', 'fail' => 'http://example.com/test.php');
php > echo preg_match('/^\/(.*?)\.php$/', $test['pass']);
True
php > echo preg_match('/^\/(.*?)\.php$/', $test['fail']);
False
0

精彩评论

暂无评论...
验证码 换一张
取 消