write_php_ini (function)

Last updated: Fri, Apr 14, 2023 4:57 pm
Return to Knowledgebase


Takes an associative array of configuration values and a file path as arguments, and writes the values to a ini file




# Parameter Data Type Required Description
1 $array array Yes Associative array of arguments
2 $file string Yes The name of the file you wish to write



Further Documentation:

Note. This will create the file even if it doesn't exist. It is also recommended that you call your ini files ini.php so they cannot be read through the browser.
Notice if you do 

1],"settings.ini"); ?>

you can navigate to that file in the browser and read it, but with 

1],"settings.ini.php"); ?>

you cannot.

The function takes two parameters: $array, which is an associative array of configuration values, and $file, which is the file path to write the values to.

The function initializes an empty array called $res, which will store the formatted configuration values.

The function then loops through each key-value pair in the $array. If the value is an array, the function adds a section header with the key, and then loops through the sub-array to add each key-value pair as a configuration line. If the value is not an array, the
function simply adds a configuration line with the key and value.

For each configuration line, the function formats the line as "key = value", where the value is wrapped in double quotes if it is not a numeric value.

Finally, the function uses the "safefilerewrite" function to write the formatted configuration lines to the specified file.

Overall, this function provides a simple and convenient way to write configuration values to an ini file, using an associative array to specify the values. The resulting file can then be used to configure PHP settings for a web application.