是否有可能重写php文件使用fwrite不删除php注释


Is it possible rewrite php file using fwrite without removing php comments?

我有一个php文件,里面有一些注释

<?php
    $test = array(
     'LBL_TEXT' => 'text',//test comment
     'LBL_FOO' => 'foo'  
    );

现在我需要更新'LBL_TEXT'值(文本)上面的文件不删除注释('//测试注释')。是否可以使用fwrite()或其他方法

所以你需要像

<?php
$data = file_get_contents("foo.php");
$data = so something clever to automatically change string as desired;
file_put_contents("foo.php",$data);
?>