The .php file contains code like:
<?php
return array(
// commments...
'some_item' => 'abc',
// commments...
'some_other_item' => array(1, 2, 3),
...
);
What’s the best way to “parse” this file somehow from within my PHP application, and be able to update data in it, without breaking formatting, code etc. ?
$content = require($file);will get the file’s content (beware of relative paths andrequirevsincludesemantics).file_put_contents($file, '<?php return ' . var_export($content, true) . ';');will write the content back to the file, but formatting will change. If you really need to keep the formatting, you could look into PHP Beautifier. It’s not a perfect solution though.