下面二款php 正则来表达式来处理url匹配的代码,希望对你有点帮助.
- <?php
- $url = 'http://www.phpfensi.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.phpfensi.com, http://img.baidu.com/logo.ico';
-
- $pattern = "|http://[^,]+?.ico,?|U";
- preg_match_all($pattern, $url, $matches);
- print_r($matches);
-
-
- Array
- (
- [0] => Array
- (
- [0] => http:
- [1] => http:
- )
-
- )