1 <?php
2 echo '<pre>';
3
4 $str = '<ul>hello world<li>hi</li><li>hello</li></ul>';
5 $pattern = '~<li>.*</li>~';
6 preg_match($pattern,$str,$matches);
7 var_dump($matches);
8 /*
9 array(1) {
10 [0]=>
11 string(25) "<li>hi</li><li>hello</li>"
12 }
13 */
14
15 $pattern1 = '~<li>.*?</li>~';
16 preg_match($pattern1,$str,$matches1);
17 var_dump($matches1);
18 /*
19 array(1) {
20 [0]=>
21 string(11) "<li>hi</li>"
22 }
23 */
24
25 $pattern2 = '~<li>.*</li>~U';
26 preg_match($pattern2,$str,$matches2);
27 var_dump($matches2);
28 /*
29 array(1) {
30 [0]=>
31 string(11) "<li>hi</li>"
32 }
33 */
34
35 $pattern3 = '~<li>.*?</li>~U';
36 preg_match($pattern3,$str,$matches3);
37 var_dump($matches3);
38 /*
39 array(1) {
40 [0]=>
41 string(25) "<li>hi</li><li>hello</li>"
42 }
43 */