第1个回答 2015-07-09
function replace_text($search , $replace , $text){
$content =file_get_contents($text);
$res = str_replace($search,$replace,$content);
file_put_contents($text,$res);
}
外部
$this->replace_text('hello', 'hi', '123.php');
如果是复杂的正则替换 把 str_replace 改成preg_replace ,
原理是这样需要过滤,优化操作自己添加