怎么替换.body里面的内容,有什么好函数可以简单实现?a.htm的代码如下:......
<div class="head"></div>
<div class="body">hello word</div>
<div class="foot"></div>
.......我想替换成其他内容(由一个php文件post过来),例如.......
<div class="head"></div>
<div class="body">
<span>good day</span>
<p>中华人民共和国</p>
</div>
<div class="foot"></div>
........
<div class="head"></div>
<div class="body">hello word</div>
<div class="foot"></div>
.......我想替换成其他内容(由一个php文件post过来),例如.......
<div class="head"></div>
<div class="body">
<span>good day</span>
<p>中华人民共和国</p>
</div>
<div class="foot"></div>
........
<div class="head"></div>
<div class="body"><?php echo $_REQUEST[名称]?></div>
<div class="foot"></div>
.......
{
$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');
preg_match_all('|<div class="body">([^(</div)]*?)</div>]+>|iSU', $str, $out);
if( $out[0][1] )$str = str_replace($out[0][1], $replacestr, $str);
// 或者直接用这个
preg_replace('|(<div class="body">)(^<]+)(</div>)|iSU', "\${1}" . 替换后的内容 . "\$3", $str);
如果考虑到以后的维护建议自己写个函数或者类 方便以后的维护。