这2段代码是在html中,把html通过file_get_contents下载下来后提取其中的数据,网页地址:http://rate.taobao.com/user-rate-39512.htm
第一个是:提取其中的a标签中的 5810
<a href="#" class="J_show_list J_MakePoint" data-point-val="tbrate.2.2.1" data-param='timeLine=-7&result=1'>5810</a>第二个是:提取其中的a标签中的 23510
<a href="#" class="J_show_list J_MakePoint" data-point-val="tbrate.2.3.1" data-param='timeLine=-30&result=1'>23510</a>

解决方案 »

  1.   

    [User:root Time:19:35:14 Path:/home/liangdong/php]$ cat preg.php 
    <?php
    $str = <<<EOF
    <a href="#" class="J_show_list J_MakePoint" data-point-val="tbrate.2.2.1" data-param='timeLine=-7&result=1'>5810</a>
    <a href="#" class="J_show_list J_MakePoint" data-point-val="tbrate.2.3.1" data-param='timeLine=-30&result=1'>23510</a>
    EOF;
    preg_match_all('/<a.*class="J_show_list J_MakePoint".*>(.*)<\/a>/iUs', $str, $matches);
    print_r($matches);
    ?>
      

  2.   

    $url = 'http://rate.taobao.com/user-rate-39512.htm';
    $s = file_get_contents($url);
    preg_match_all('#class="J_show_list J_MakePoint".+tbrate\.2\.[23]\.1.+>(\d+)</a>#isU', $s, $r);
    print_r($r[1]);Array
    (
        [0] => 5251
        [1] => 23124
    )
      

  3.   


    我要同时匹配这两段字符,该如何写正则呢
    <a href="http://ratehis.taobao.com/user-rate-39512--isarchive|true--detailed|1--goodNeutralOrBad|1--timeLine|-211--receivedOrPosted|0--buyerOrSeller|0.htm#RateType" class="J_MakePoint" data-point-val="tbrate.2.5.1">4508530</a><a href="#" class="J_show_list J_MakePoint" data-point-val="tbrate.2.4.1" data-param='timeLine=-210&result=1'>289048</a>
    都是需要提取<a>标签内的数字,如第一个中搞定4508530和第二个中的289048,用一个正则匹配
      

  4.   

    preg_match_all('#class=".*J_MakePoint".+tbrate\.2\.\d+\.1.+>(\d+)</a>#isU', $s, $r);