下面二款php教程 正則來表達式來處理url匹配的代碼,希望對你有點幫助。
<?php
$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.111cn.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
))