2

I have some php file and it contains some comments.

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

Now I need to update 'LBL_TEXT' value(text) above file without removing comment('//test comment'). Is it possible using fwrite() or some other way.

6
  • What prevents you from using any text-editor to edit the file as desired? Commented Sep 19, 2015 at 14:17
  • It is possible, but not easy. Commented Sep 19, 2015 at 14:18
  • @Fred-ii- Its my typo mistake. I updated. Thanks Commented Sep 19, 2015 at 14:28
  • 1
    You're welcome and I had to be sure. You would be amazed as to what people really use sometimes ;-) Commented Sep 19, 2015 at 14:30
  • @MBaas I have hundreds of similar files to update with content. I am writing an automated script to do this work instead of doing this manually Commented Sep 19, 2015 at 14:36

1 Answer 1

0

So you will need something like

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

?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.