Mudsaf Posted January 8, 2013 Share Posted January 8, 2013 (edited) 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 January 8, 2013 by Mudsaf Link to comment Share on other sites More sharing options...
kanchatchai Posted January 8, 2013 Share Posted January 8, 2013 May be use readfile and explode. Link to comment Share on other sites More sharing options...
Mudsaf Posted January 8, 2013 Author Share Posted January 8, 2013 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 comment Share on other sites More sharing options...
boen_robot Posted January 8, 2013 Share Posted January 8, 2013 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. 1 Link to comment Share on other sites More sharing options...
kanchatchai Posted January 8, 2013 Share Posted January 8, 2013 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 likefile_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 comment Share on other sites More sharing options...
birbal Posted January 8, 2013 Share Posted January 8, 2013 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 comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now