[eluser]sunnyd[/eluser]
Hi all,
I have a config file which looks like so:
$GLOBALS['dbname'] = 'test';
$GLOBALS['dbuser'] = 'test1';
$GLOBALS['dbpass'] = 'test2';
Is there a regex function that I can use to properly extract for example dbname and its value and save that into a separate variables.
At the moment, this is the code that I am trying to use:
Code:
$file_handle = fopen($myfile, 'r');
while (!feof($file_handle)) {
$line = fgets($file_handle);
$parts = split("=", $line);
if (isset($parts[0]) && isset($parts[1])) {
$key = trim(preg_replace("/$GLOBALS\[(['^']]+)\]/", "", $parts[0]));
$value = trim(str_replace(array('"', "'", ";"), "", $parts[1]));
$config[$key] = $value;
}
}
fclose($file_handle);
So far, if i try $config['dbname'], the value is empty. Am I doing something wrong?