Php:
'20120823','secretKey' => '92fe5927095eaac53cd1aa3408da8135','areaname' => 'China',);
Now I want to write a Common. php setConfig ($ fileName, $ value) method to modify the value of areaname. $ FileName is the name of the Config. php file, and $ value is the replaced value. I don't know how to write it ??
Reply to discussion (solution)
File_get_contents ()
File_put_contents ()
Function setConfig ($ fileName, $ value) {ob_start (); $ a = @ include ($ fileName); ob_end_clean (); if (! Is_array ($ a) trigger_error ("Invalid data file", E_USER_ERROR); $ a ['areaname'] = $ value; file_put_contents ($ fileName ,'
However, due to the limitations of your solution, this function is not common.
For example, you cannot modify the secretKey.
It is recommended to rewriteFunction setConfig ($ key, $ value, $ fileName = 'config. php') {ob_start (); $ a = @ include ($ fileName); ob_end_clean (); if (! Is_array ($ a) trigger_error ("Invalid data file", E_USER_ERROR); $ a [$ key] = $ value; file_put_contents ($ fileName ,'
There is a positive solution upstairs. good developers must have an idea on universality.