Skip to content

Instantly share code, notes, and snippets.

@artlung
Created February 25, 2010 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlung/314782 to your computer and use it in GitHub Desktop.
Save artlung/314782 to your computer and use it in GitHub Desktop.
<?php
$paths = array(
// an array of paths to wp-config.php files
'example.com/blog/wp-config.php',
);
$root = "/usr/home/artlung/public_html/";
$index = 0;
$look_fors = array(
'DB_NAME',
'DB_USER',
'DB_PASSWORD',
'DB_HOST',
);
for($index = 0; $index < count($paths); $index++) {
$filename = $root . $paths[$index];
//print $filename;
$lines = file($filename, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
//$lines = explode(';',$contents);
$useful_lines = array();
//keep look_fors lines
foreach($lines as $line) {
foreach($look_fors as $look_for) {
//print $look_for . $line;
if(strpos($line,$look_for)!==FALSE && strpos($line,'define')!==FALSE) {
$useful_lines[] = $line;
// print $line;
}
}
}
//print $filename . "<br />";
for ($i=0; $i<count($useful_lines); $i++) {
$string = $useful_lines[$i];
$pattern = '/define\((.*),(.*)\);.*.*/';
$replacement = '$values[$filename][$1] = $2;';
$line = preg_replace($pattern,$replacement,$string);
eval($line);
$parts = split("/",$paths[$index]);
$values[$filename]['hostname'] = $parts[0];
}
}
print_r($values);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment