<p>
今天有个小朋友问了我这么个问题,哈哈,竟然还有这总需求,好吧!
<?php $file_content = file_get_contents('test.php'); $pattern = '#function\s+test\s*\(\s*\)\s*\{[^\}]+\}#'; $file_content = preg_replace($pattern, 'function test(){ return "bbb"; }', $file_content);file_put_contents('test.php', $file_content); ?>