php匹配url正则表达式

2024-11-30 01:58:50
推荐回答(3个)
回答1:

$url = 'http://www.test.com/icons/favicon-54.ico, http://www.baidu.com/bb, http://www.sina.com, https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/logo.ico';

$pattern = "|http:\/\/[^,]+?\.ico,?|U";
preg_match_all($pattern, $url, $matches);
print_r($matches);

输出结果:

Array
(
[0] => Array
(
[0] => http://www.test.com/icons/favicon-54.ico
[1] => https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/logo.ico
)

)

回答2:

不是非常准确的方法
/^http://(.+)\.ico$/U

回答3:

^http:\/\/.*?\.ico$