21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
//重复标签
$string = "<tr width='100'>1</tr><tr width='98'>2</tr>";
//贪吃模式
preg_match_all('#<tr[^>]*>.*</tr>#is', $string, $matches);
print_r($matches);
//非贪吃模式
//这里.*?中的?表示与默认的模式相反,如果默认配置是贪吃,这里就是非贪吃模式
//如果默认配置是非贪吃,这里就是贪吃模式(我们取默认配置是贪吃,请注意和其他地方?的意义区别)
preg_match_all('#<tr[^>]*>.*?</tr>#is', $string, $matches);
print_r($matches);
//嵌套标签
$string2 = "<table width='300'>1<table width='150'>2</table></table>";
//贪吃模式
preg_match_all('#<table[^>]*>.*</table>#is', $string2, $matches);
print_r($matches);
//非贪吃模式
preg_match_all('#<table[^>]*>.*?</table>#is', $string2, $matches);
print_r($matches);
?>
preg_match_all('/([^\?|^>]>){1}([^>|^<\?|^\r\n|^if]+?)([<|<\/][^\?])/U', $string, $arr);
print_R($arr);
preg_replace('/(>)([^>|^<\?|^\r\n][^\d]+?)([<|<\/])/i', "$1<?php print_R(\$translate->_(\"$2\")) ?>$3", $data);