msgbartop
better late than never
msgbarbottom

Jun 06 正则表达式U修正符。

echo '<pre>';  

 $str = '<ul>hello world<li>hi</li><li>hello</li></ul>';  

 $pattern = '~<li>.*</li>~';  

 preg_match($pattern,$str,$matches);  

 var_dump($matches);  

 /*  

 array(1) {  

  [0]=>  

  string(25) "<li>hi</li><li>hello</li>"  

}  

*/ 

$pattern1 = '~<li>.*?</li>~';  

preg_match($pattern1,$str,$matches1);  

var_dump($matches1);  

/*  

array(1) {  

  [0]=>  

  string(11) "<li>hi</li>"  

}  

*/ 

$pattern2 = '~<li>.*</li>~U';  

preg_match($pattern2,$str,$matches2);  

var_dump($matches2);  

/*  

array(1) {  

  [0]=>  

  string(11) "<li>hi</li>"  

}  

*/ 

$pattern3 = '~<li>.*?</li>~U';  

preg_match($pattern3,$str,$matches3);  

var_dump($matches3);  

/*  

array(1) {  

  [0]=>  

  string(25) "<li>hi</li><li>hello</li>"  

}  

*/

事实证明,加了U,原来是贪婪匹配的变成非贪婪匹配,非贪婪匹配的却变成了贪婪匹配。



Leave a Comment




*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word