21,886
社区成员
发帖
与我相关
我的任务
分享
......
<div class="head"></div>
<div class="body">hello word</div>
<div class="foot"></div>
.......
.......
<div class="head"></div>
<div class="body">
<span>good day</span>
<p>中华人民共和国</p>
</div>
<div class="foot"></div>
........
preg_replace('|(<div class="body">)(^<]+)(</div>)|iSU', "\${1}" . 替换后的内容 . "\$3", $str);
// 或者直接用这个
preg_replace('|(<div class="body">)(^<]+)(</div>)|iSU', "\${1}" . 替换后的内容 . "\$3", $str);
preg_match_all('|<div class="body">([^(</div)]*?)</div>]+>|iSU', $str, $out);
if( $out[0][1] )$str = str_replace($out[0][1], $replacestr, $str);
// +------ 我以前写的一个替换函数
function file_modify($search_contents, $replace_contents, $filename)
{
$fp = file_get_contents($filename);
$new_fp = str_replace($search_contents, $replace_contents, $fp);
file_put_contents($filename, $new_fp);
}
// +------ 用法
file_modify('sdf hjhj', 'sdf_test hjhj_test', 'test10.html');