Welcome Guest, Not a member yet? Register   Sign In
Small help with regex code
#3

[eluser]Christopher Blankenship[/eluser]
And here would be away to fix the code so it would work.
Code:
<?php
$myfile = 'globals.php';
$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(str_replace('$GLOBALS[\'', "", $parts[0]));
                    $key = trim(str_replace('\']', "", $key));
                    $value = trim(str_replace(array('"', "'", ";","]"), "", $parts[1]));
                    $config[$key] = $value;
                }
            }
            fclose($file_handle);

print_r($config);

?>

globals.php
Code:
<?php

$GLOBALS['dbname'] = 'test';
$GLOBALS['dbuser'] = 'test1';
$GLOBALS['dbpass'] = 'test2';

?>

This would output the following:

Array ( [dbname] => test [dbuser] => test1 [dbpass] => test2 )


Messages In This Thread
Small help with regex code - by El Forum - 03-07-2010, 05:41 PM
Small help with regex code - by El Forum - 03-08-2010, 12:08 AM
Small help with regex code - by El Forum - 03-08-2010, 12:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB