开发者

preg_match & regex fail to catch full url with filename "a.jpg_x.jpg"

I use in my code :

preg_match( '!http://[^?#]+\.(?:jpe?g|png|gif)!Ui' , $str[1], $results );

It work in most cases except:

src='http://www.domain.com/Pic/folder1/folder2/a.jpg_x.jpg' alt=

I get:

......older2/a.jpg

I need:

.....older2/a.jpg_x.jpg
开发者_运维问答

any ideas?

Thanks in advance


$str = "src='http://www.domain.com/Pic/folder1/folder2/a.jpg_x.jpg' alt=";
preg_match("!http://[^?#']+\.(?:jpe?g|png|gif)!i", $str, $results );
var_dump($results);


I believe you need the end of expression character "$"

eg. preg_match( '!http://[^?#]+.(?:jpe?g|png|gif)$!Ui' , $str[1], $results );

NOTE: This is completely untested. Sorry I'm posting from my phone so I cant test.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜