只是想知道如何提取或匹配特定的文件類型,因爲有很多畸形的URL和目錄。如何捕獲格式不正確的URL中的文件類型
所以我需要一個很好的正則表達式來匹配真正的正則表達式。
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 only the first .jpg
http://domain.com/1/.jpg <-not match
http://domain.com/.jpg.jpg <- not match
/1/.jpg <-not match
/.jpg.png <-match the first jpg
/image.jpg.png <-match the first jpg
我想用這段代碼:
preg_match_all('([a-zA-Z0-9.-_](jpg))i', $url, $matches);
任何想法?
這工作很好,但我忘了一些網址是不完整的,只是引用目錄像/1/.jpg.gif – greenbandit 2013-04-18 02:33:30