php求一个正则表达式获取网站页面上所有 <A>check user</a>
问题来了 如果仅仅是url比较好办
但是a标记如何获取?小弟比较菜 有可能出现这样的情况<A href="javascrpti:void(0)">check user</a><A href="javascrpti:void(0)">   ----->分行也无法获取
check user
</a>或者断裂的标记
<A title=""                      ----->分行也无法获取 title,class不规则
class="sytels">check user</a>这样也没有办法 小弟比较菜 就高手给我一个正则 能获得所有html A标记 (大小写)的这里先谢过了

解决方案 »

  1.   

    <(a|A)[\s]{0,1}[\w=":()]*>[\n\r\n]*(check user)[\n\r\n]*</(a|A)>我试着写了一个!
      

  2.   


    //纯手写,没经测试preg_match_all('/<a[\d\D]*>check user<\/a>/i',$string,$matches);print_r($matches[0]);
      

  3.   


    preg_match_all('/<a[^>]*>[^<]*<\/a>/i',$string,$matches);print_r($matches[0]);没试过
      

  4.   

    gxg
    x
    gx
      

  5.   


    preg_match_all('/<a.+?>check user<\/a>/is',$str,$arr);
      

  6.   

    <?php
    $str = '
    有可能出现这样的情况
    <A href="javascrpti:void(0)">check user</a>
    <A href="javascrpti:void(0)">
    check user
    </a>
    或者断裂的标记
    <A title=""
    class="sytels">check user</a>';
    preg_match_all('#<a[^>]*>\s*check user\s*</a>#i',$str,$m);
    var_dump($m);
    ?>
      

  7.   

    preg_match_all('/<a.+?>check user<\/a>/is',$str,$arr);
      

  8.   

    https://groups.google.com/group/cocoa4mac
      

  9.   

    https://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4machttps://groups.google.com/group/cocoa4mac
      

  10.   

    $pattern = '|<a[^>]*>check user</a>|isU';没测试,问题应该不大
      

  11.   


    //------------------------------------------------*
    //函数:通过标签抓取页面中所有的元素,例如图片
    //参数:正则表达式,页面内容(要用函数AddsLashes转译)
    //返回:抓取后的内容数组(key,value)
    Function GetMeta($Regi,$Body){
    $ArrTmp=Array();$ArrInfo=Array();
    Preg_match_all("/".$Regi."/is", Stripslashes($Body), $ArrTmp);
    Foreach($ArrTmp[2] as $Tmp){
    $ArrInfo[]=Str_iReplace(Chr(10),"",$Tmp);
    }
    Return $ArrInfo;
    }
    $aa=GetMeta("<a.[^>]*>.[^<]*<\/a>","需要抓取的内容");