<body>
   <div>
      <div>
         <div>
           <div>111
           </div>222      
         </div>3333
      </div>444
    </div>
</body>
而我要匹配出这里面的4个div
结果是:
<div>111</div>
<div><div>111</div>222</div>
<div><div><div>111</div>222</div>3333</div>
<div><div><div><div>111</div>222</div>3333</div>444</div>我就想到爆头了, 大伙也试下吧.

解决方案 »

  1.   

    用simple_html_dom吧。<?php
    require('simple_html_dom.php');
    $html = str_get_html('<body><div><div><div><div>111</div>222</div>333</div>444</div></body>');
    $a = $html->find('div', 0);
    $b = $html->find('div', 1);
    $c = $html->find('div', 2);
    $d = $html->find('div', 3);
    echo $a->outertext.'<hr />'; 
    echo $b->outertext.'<hr />'; 
    echo $c->outertext.'<hr />'; 
    echo $d->outertext.'<hr />'; 
    ?>