preg_replace($pattern, $replacement, $content) 修饰符的奇葩作用

$str = "<span>lin</span> == <span>3615</span>";
$pattern = "/<span>(.*)<\/span>/";
$str = preg_replace($pattern, "<span class='fuck'>$1</span>", $str);
print_r($str);

$pattern 中没有问号

结果为:<span class='fuck'>lin</span> == <span>3615</span>

$str = "<span>lin</span> == <span>3615</span>";
$pattern = "/<span>(.*?)<\/span>/";
$str = preg_replace($pattern, "<span class='fuck'>$1</span>", $str);
print_r($str);

$pattern 中有问号(相当于防止贪婪匹配)

结果为:<span class='fuck'>lin</span> == <span class='fuck'>3615</span>

$str = "<span>lin</span> == <span>3615</span>";
$pattern = "/<span>(.*)<\/span>/U";
$str = preg_replace($pattern, "<span class='fuck'>$1</span>", $str);
print_r($str);

$pattern 中无问号( U 防止贪婪匹配)

结果为:<span class='fuck'>lin</span> == <span class='fuck'>3615</span>

$str = "<span>lin</span> == <span>3615</span>";
$pattern = "/<span>(.*?)<\/span>/U";
$str = preg_replace($pattern, "<span class='fuck'>$1</span>", $str);
print_r($str);

$pattern 中有问号( U 防止贪婪匹配),相当于失去了U的意义

<span class='fuck'>lin</span> == <span>3615</span>
上一篇:Mybatis操作oracle数据库的一些坑


下一篇:测试12.2.0.1RAC PDB级别的Failover