Skip to content

Instantly share code, notes, and snippets.

@GusAntoniassi
Last active March 15, 2018 18:09
Show Gist options
  • Save GusAntoniassi/46f4d113bcbe82fb3b618d0f2d348fbb to your computer and use it in GitHub Desktop.
Save GusAntoniassi/46f4d113bcbe82fb3b618d0f2d348fbb to your computer and use it in GitHub Desktop.
Getting a server's configuration parameters in .ini format
<?php
/**
* Run this script to get a server's configuration parameters in .ini format
* Keywords: ini_get ini_get_all function php get configuration data from php.ini format like config
*/
$ini = (ini_get_all());
foreach ($ini as $name => $item) {
$val = $item['global_value'];
$prefix = '';
$suffix = '';
$hasQuotes = false;
if (!is_numeric($val)) {
if (!empty($val)) {
$hasQuotes = true;
} else {
$val = 'Off';
}
}
// Prevent quotes from values such as "128K", "1024M" "3G"
if (preg_match('/\d+[KMG]/', $val)) {
$hasQuotes = false;
}
if ($hasQuotes) {
$prefix = '"';
$suffix = '"';
}
echo $name . ' = ' . $prefix . $val . $suffix . '<br/>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment