Jump to content

Using PHP to edit PHP? / Can I use fopen() to edit specific parts of a php file?


Aaron_Escobar

Recommended Posts

Hi everyone, I have a php control panel which I'm going to use to make quick edits to a configuration.php file for my custom content managing php framework.

The settings that I want to change with the control panel will be actually changing definitions in the configuration.php file. Definitions like:

define("SITE_OWNER", "John Doe");
define("SITE_NAME", "MyDomain.com');

Where do I start? Can I use fopen() to edit specific parts of the php file?

I would go with:

$file = file('filename.php');

 

file will take your file and store each line into an array. That means $file is an array. Each entry in the array would be a new line. Loop through it and make the necessary changes. After that, just use file_put_contents to write it back into the file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.