php - How to catch filetypes in malformed URLs -
just wondering how can extract or match specific file type, since there lot of malformed urls , directories.
so need regex match real ones.
http://domain.com/1/image.jpg <-match .jpg http://domain.com/1/image_1.jpg/.gif <-match first .jpg http://domain.com/1/image_1.jpg/image.png <-match first .jpg http://domain.com/1/image_1.jpg <-match .jpg http://domain.com/1/image.jpg.jpeg <-match first .jpg http://domain.com/1/.jpg <-not match http://domain.com/.jpg.jpg <- not match /1/.jpg <-not match /.jpg.png <-match first jpg /image.jpg.png <-match first jpg
i'm trying piece of code:
preg_match_all('([a-za-z0-9.-_](jpg))i', $url, $matches);
any ideas?
preg_match('(^(http://domain.com/\w.*?\.jpg))i', $url, $matches);
this match start of string first .jpg
. filename part must start letter, number, or _
.
Comments
Post a Comment