请教这个用正则怎么匹配

WBOY
Release: 2016-06-13 13:40:46
Original
818 people have browsed it

请问这个用正则如何匹配?
目的是匹配网页源代码中的href,大概有三种类型
类型一:


 ---换行---
 ---换行---
一一一一(seo)
类型二:

 [引蜘蛛]onclick="atarget(this)" class="xst" >二二二二
类型三:


 三三三

自己写了个$pattern = "/".preg_quote(' ','/')."(.*)"."\n"." ".preg_quote('
','/').".+".preg_quote('class="xst" >','/').'/i';
但是不能完全匹配。。求高手帮忙

我说下我的思路先:
以 或 开头,然后是多余的字符然后换行(0个或多个),然后是结束。。但是匹配的时候经常是除了href的内容外 还会带上其它的


------解决方案--------------------
PHP code

$str=

<a href="http://bbs.111.com/thread-11.html" onclick="atarget(this)" class="xst">一一一一(seo)</a>
类型二:
<th class="common">
 <em>[<a href="http://www.444.com/forum.php?">引蜘蛛</a>]</em><a href="http://www.444.com/thread-263.html" onclick="atarget(this)" class="xst">二二二二</a>
类型三:
</th><th class="common">

 <a href="http://www.555.com/thread-161.html" style="color: #EC1282" class="xst" target="_blank">三三三</a>
 </th><th class="aa">

 <a href="http://www.555.com/thread-161.html" style="color: #EC1282" class="xst" target="_blank">三三三</a>
html;
preg_match_all('/(?:</th><th class="new|common">).+<a href="(%5B%5E" print_r class="clear">
                 
              
              
        
            </a>
</th>
Copy after login
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template