Jump to content

PHP Config edit


Recommended Posts

Is it possible to edit certain part of PHP config page and get the certain value from it. Example i have config file (i know it would not work since no actual code but i think you will get my point here). So im wondering is it possible change CONSTRUCTION = false part to true with PHP whitout editing rest of the file or keeping rest of the file same? OLD

1: SQL2: SQL-DB-SELECT3: SECURITY4: CONSTRUCTION = false5: FOOTER  = "© 2012" . $website

NEW

1: SQL2: SQL-DB-SELECT3: SECURITY4: CONSTRUCTION = true5: FOOTER  = "© 2012" . $website

Edited by Mudsaf
Link to post
Share on other sites

Could you give me small example like script.php

<?php//Code here?>

example.php file with data

1: potato2: carrot 3: tomato

And change the line to

1: potato 2: slenderman3: tomato

Link to post
Share on other sites

As hinted by kanchatchai, there isn't exactly a native way of reading and writing configuration.There are however various libraries that allow you to store configuration in various formats, such as PEAR::Config or Zend\Config.If you want to avoid using libraries, the easiest way is to store the configuration in an array. Use something like

file_put_contents('config.php', '<?php return ' . var_export($config, true));

to write the file, and simply use

$config = include 'config.php';

to read it.Manipulate it as you would any other array.

  • Like 1
Link to post
Share on other sites
As hinted by kanchatchai, there isn't exactly a native way of reading and writing configuration. There are however various libraries that allow you to store configuration in various formats, such as PEAR::Config or Zend\Config. If you want to avoid using libraries, the easiest way is to store the configuration in an array. Use something like
file_put_contents('config.php', '<?php return ' . var_export($config, true));

to write the file, and simply use

$config = include 'config.php';

to read it. Manipulate it as you would any other array.

thanks for advice boen_robot
Link to post
Share on other sites

You can also use simplexml to parse config files in XML which is more readable and covenient for complex config files (nested config)http//php.net/simplexml

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...