下面二款php教程 正则来表达式来处理url匹配的代码,希望对你有点帮助。
$url = 'http://www.baidu.com/zongzi/oo.html';
$n = preg_match_all("/http:[/]{2}[a-z]+[.]{1}[a-zd-]+[.]{1}[a-zd]*[/]*[A-Za-zd]*[/]*[A-Za-zd]*[.]*html/",$url,$array);
var_dump($array);
?>
例子
$url = 'http://www.test.com/icons/favicon-54.ico, http://www.baidu.com/bb, http://www.111com.net, http://img.baidu.com/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] => http://img.baidu.com/logo.ico
))