Reputation: 312
I am writing a PHP library and to increase its portability and robustness I would like to be able to read the php.ini file to access the installation settings.
Is there a simple way to do this or do I need to do this the hard way and write code to parse this myself?
Thanks
Upvotes: 5
Views: 5344
Reputation: 1427
PHP has a nice support for INI files. Along with the php_ini_loaded_file()
you can get the details of current ini file.
<?php
// get path to the ini file
$inipath = php_ini_loaded_file();
// Parse with sections
$ini_array = parse_ini_file($inipath , true);
print_r($ini_array);
?>
http://php.net/manual/en/function.parse-ini-file.php
http://php.net/manual/en/function.php-ini-loaded-file.php
Upvotes: 6