Home  >  Article  >  php教程  >  PHP完美的提取链接正则

PHP完美的提取链接正则

PHP中文网
PHP中文网Original
2016-05-25 16:58:111416browse

php代码

function match_links($document) {    
preg_match_all("']+))[^>]*>?(.*?)'isx",$document,$links);                        
while(list($key,$val) = each($links[2])) {
if(!empty($val))
$match['link'][] = $val;
}
while(list($key,$val) = each($links[3])) {
if(!empty($val))
$match['link'][] = $val;
}        
while(list($key,$val) = each($links[4])) {
if(!empty($val))
$match['content'][] = $val;
}
while(list($key,$val) = each($links[0])) {
if(!empty($val))
$match['all'][] = $val;
}                
return $match;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn