日期:2014-05-17  浏览次数:20544 次

字符串截取
$subject = '<div class="superStar" id="test_0">
  you dead!
<div class="show">hello</div>
<span>james</span>
</div>
            <div class="superStar" id="test_1">
shit!
<div class="contne">hi</div>
<ul><li>list</li></ul>
            </div>';

$pattern = '/这里正则如何写/';
preg_match($pattern, $subject, $matches);
print_r($matches);

$pattern_1 = '/这里正则如何写/';
preg_match($pattern_1, $subject, $matches);
print_r($matches);

分别取到结果如下:
数据一:
you dead!
<div class="show">hello</div>
<span>james</span>

数据二:
shit!
<div class="contne">hi</div>
<ul><li>list</li></ul>


请问正则要如何写才能取出上在的两个DIV中的内容呢。

------解决方案--------------------
<?php
$subject = '<div class="superStar" id="test_0">
                 you dead!
                <div class="show">hello</div>
                <span>james</span>
            </div>
            <div class="superStar" id="test_1">
                shit!
                <div class="contne">hi</div>
                <ul><li>list</li></ul>
            </div>';
preg_match_all('/<div[^>]+>(([^<]*