$regb2 = '\<h3 class\=\"t\"\>(.*)\<\/h3\>';
preg_match_all("/$regb2/is", $ruleb1[0],$ruleb2);

print_r($ruleb2); 只取到了一个h3   请问是什么原因

解决方案 »

  1.   

    <table><h3>...</h3></table>
    <table><h3>...</h3></table>
    <table><h3>...</h3></table>
    <table><h3>...</h3></table>
    <table><h3>...</h3></table>还是只取到了第一个      不加?  取到第一个  下面的几个table都能取到   加了 就取到第一个h3
      

  2.   

    你所贴的并不完整,至少h3的class是没显示的,我改动一下$str = '<table><h3 class="t">...</h3></table>
    <table><h3 class="t">...</h3></table>
    <table><h3 class="t">...</h3></table>
    <table><h3 class="t">...</h3></table>
    <table><h3 class="t">...</h3></table>';$regb2 = '\<h3 class\=\"t\"\>(.*?)\<\/h3\>';
    preg_match_all("/$regb2/is", $str,$ruleb2);print_r($ruleb2);
    匹配到5个Array
    (
        [0] => Array
            (
                [0] => <h3 class="t">...</h3>
                [1] => <h3 class="t">...</h3>
                [2] => <h3 class="t">...</h3>
                [3] => <h3 class="t">...</h3>
                [4] => <h3 class="t">...</h3>
            )    [1] => Array
            (
                [0] => ...
                [1] => ...
                [2] => ...
                [3] => ...
                [4] => ...
            ))
      

  3.   

    <?php
    $str = "<table><h3>a</h3></table>
    <table><h3>b</h3></table>
    <table><h3>c</h3></table>
    <table><h3>d</h3></table>
    <table><h3>e</h3></table>
    ";
    $pattern = '/\<h3\>(.*?)\<\/h3\>/';
    preg_match_all($pattern, $str, $matches);
    echo '<pre>';
    print_r($matches);
    ?>
      

  4.   

    $objb = file_get_contents($siteUrlb);
    echo '网站加载成功...';$regb = '\<div id\=\"container\"\>(.*)\<\/div\>';
    preg_match("/$regb/is", $objb,$ruleb);

    $regb1 = '\<table cellpadding\=\"0\" cellspacing\=\"0\" class\=\"result\" id\=\"\d\" \>(.*)\<\/table\>';
    preg_match("/$regb1/is", $ruleb[0],$ruleb1);


    $regb2 = '\<h3 class\=\"t\"\>(.*?)\<\/h3\>';
    preg_match_all("/$regb2/is", $ruleb1[0],$ruleb2);
    print_r($ruleb2[0]);加?号是取消贪婪模式了    我这经过了几层子模式  你看是不是上面那里有问题 还是网站里有相似的标签导致的问题
      

  5.   

    echo $ruleb1[0];  //贴出结果