skip blank space (regex)
Posted: Thu Oct 25, 2007 7:28 am
Hi,
I'm working on a function that reads a configuration file. First it reads the whole file and splits up every line into an array, then it reads every line for a configuration option and its respective value.
I.e. the configuration file could look like this:
each line is then read using the following php code in a foreach loop
This works fine, although I would like it to be able to read config files that doesn't follow this strict 'option*space*=*space*value' pattern. eg it should be able to read a line, that looks something like this as well
where it doesn't care whether there are four blanks or no blanks at all.
Any help would be great
thanks.
I'm working on a function that reads a configuration file. First it reads the whole file and splits up every line into an array, then it reads every line for a configuration option and its respective value.
I.e. the configuration file could look like this:
Code: Select all
# Comment
cfg_option = 'value'Code: Select all
// Don't read commented or empty lines
if( substr( $line, 0, substr($string, 0, 1 - strlen( $string ) ) ) == '#' || empty( $line ) ) continue;
preg_match( '/(.*) = [\'|"](.*)[\'|"]/', $line, $values );Code: Select all
cfg_option= 'value'Any help would be great
thanks.