日期: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>
<?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[^>]+>(([^<]*