Home > php教程 > php手册 > body text

发一个从html批量提取URL超链接的函数

WBOY
Release: 2016-06-07 11:34:15
Original
1632 people have browsed it

我们在开发二代旅游CMS网站程序的过程中,遇到了需要从html批量提取URL超链接的的功能需求,于是有了下面这个函数,用到了正则,代码精炼的同时,效率还比较高,分享下
我们在开发二代旅游CMS网站程序(官网:http://www.erdaicms.com )的过程中,遇到了需要从html批量提取URL超链接的的功能需求,于是有了下面这个函数,用到了正则,代码精炼的同时,效率还比较高,分享下/*提取html中的url*/  <br> function match_links($document) {    <br> preg_match_all("']+))[^>]*>?(.*?)'isx",$document,$links);                        <br> while(list($key,$val) = each($links[2])) {<br> if(!empty($val))<br> $match['link'][] = $val;<br> }<br> while(list($key,$val) = each($links[3])) {<br> if(!empty($val))<br> $match['link'][] = $val;<br> }        <br> while(list($key,$val) = each($links[4])) {<br> if(!empty($val))<br> $match['content'][] = $val;<br> }<br> while(list($key,$val) = each($links[0])) {<br> if(!empty($val))<br> $match['all'][] = $val;<br> }                <br> return $match;<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template