Skip to content

Instantly share code, notes, and snippets.

@tomasfejfar
Created June 19, 2013 16:35
Show Gist options
  • Select an option

  • Save tomasfejfar/5815740 to your computer and use it in GitHub Desktop.

Select an option

Save tomasfejfar/5815740 to your computer and use it in GitHub Desktop.
Compare two ini files with different formats. Will sort the keys and dump php arrays. Really useful for mysql/apache conf.
<?php
/**
* INI configurations compare
*
* Usage: php compare.php file1.ini file2.ini
* Result: Will export sorted arrays into *.res files to use with normal diff tool
*/
$x = parse_ini_file($argv[1],true);
$y = parse_ini_file($argv[2],true);
ksort($x);
foreach ($x as $k => $v) {
ksort($v);
$x[$k] = $v;
}
ksort($y);
foreach ($y as $k => $v) {
ksort($v);
$y[$k] = $v;
}
file_put_contents($argv[1] . '.res', var_export(($x), 1));
file_put_contents($argv[2] . '.res', var_export(($y), 1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment