function parse_contents($contents)
	{
		if($this->fix_newlines) {
			// fix mac/dos formatted newlines
			$contents = preg_replace('!\r\n?!', "\n", $contents);
		}

		$config_data = array();
		$config_data['sections'] = array();
		$config_data['vars'] = array();

		/* reference to fill with data */
		$vars =& $config_data['vars'];

		/* parse file line by line */
		preg_match_all('!^.*\r?\n?!m', $contents, $match);
		$lines = $match[0];
		for ($i=0, $count=count($lines); $i<$count; $i++) {
			$line = $lines[$i];
			if (empty($line)) continue;

			if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
				/* section found */
				if (substr($match[1], 0, 1) == '.') {
					/* hidden section */
					if ($this->read_hidden) {
						$section_name = substr($match[1], 1);
					} else {
						/* break reference to $vars to ignore hidden section */
						unset($vars);
						$vars = array();
						continue;
					}
				} else {
					$section_name = $match[1];
				}
				if (!isset($config_data['sections'][$section_name]))
				$config_data['sections'][$section_name] = array('vars' => array());
				$vars =& $config_data['sections'][$section_name]['vars'];
				continue;
			}

			if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
				/* variable found */
				$var_name = rtrim($match[1]);
				if (strpos($match[2], '"""') === 0) {
					/* handle multiline-value */
					$lines[$i] = substr($match[2], 3);
					$var_value = '';
					while ($i<$count) {
						if (($pos = strpos($lines[$i], '"""')) === false) {
							$var_value .= $lines[$i++];
						} else {
							/* end of multiline-value */
							$var_value .= substr($lines[$i], 0, $pos);
							break;
						}
					}
					$booleanize = false;

				} else {
					/* handle simple value */
					$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
					$booleanize = $this->booleanize;

				}
				$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
			}
			/* else unparsable line / means it is a comment / means ignore it */
		}
		return $config_data;
	}
function parse_contents($contents)
	{
		if($this->fix_newlines) {
			// fix mac/dos formatted newlines
			$contents = preg_replace('!\r\n?!', "\n", $contents);
		}

		$config_data = array();
		$config_data['sections'] = array();
		$config_data['vars'] = array();

		/* reference to fill with data */
		$vars =& $config_data['vars'];

		/* parse file line by line */
		preg_match_all('!^.*\r?\n?!m', $contents, $match);
		$lines = $match[0];
		for ($i=0, $count=count($lines); $i<$count; $i++) {
			$line = $lines[$i];
			if (empty($line)) continue;

			if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
				/* section found */
				if (substr($match[1], 0, 1) == '.') {
					/* hidden section */
					if ($this->read_hidden) {
						$section_name = substr($match[1], 1);
					} else {
						/* break reference to $vars to ignore hidden section */
						unset($vars);
						$vars = array();
						continue;
					}
				} else {
					$section_name = $match[1];
				}
				if (!isset($config_data['sections'][$section_name]))
				$config_data['sections'][$section_name] = array('vars' => array());
				$vars =& $config_data['sections'][$section_name]['vars'];
				continue;
			}

			if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
				/* variable found */
				$var_name = rtrim($match[1]);
				if (strpos($match[2], '"""') === 0) {
					/* handle multiline-value */
					$lines[$i] = substr($match[2], 3);
					$var_value = '';
					while ($i<$count) {
						if (($pos = strpos($lines[$i], '"""')) === false) {
							$var_value .= $lines[$i++];
						} else {
							/* end of multiline-value */
							$var_value .= substr($lines[$i], 0, $pos);
							break;
						}
					}
					$booleanize = false;

				} else {
					/* handle simple value */
					$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
					$booleanize = $this->booleanize;

				}
				$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
			}
			/* else unparsable line / means it is a comment / means ignore it */
		}
		return $config_data;
	}
function parse_contents ( $ contents ) { if ( $ this -> fix_newlines ) { // fix mac/dos formatted newlines $ contents = preg_replace ( '!\r\n?!' , "\n" , $ contents ) ; } $ config_data = array ( ) ; $ config_data [ 'sections' ] = array ( ) ; $ config_data [ 'vars' ] = array ( ) ; /* reference to fill with data */ $ vars = & $ config_data [ 'vars' ] ; /* parse file line by line */ preg_match_all ( '!^.*\r?\n?!m' , $ contents , $ match ) ; $ lines = $ match [ 0 ] ; for ( $ i = 0 , $ count = count ( $ lines ) ; $ i < $ count ; $ i ++ ) { $ line = $ lines [ $ i ] ; if ( empty ( $ line ) ) continue ; if ( substr ( $ line , 0 , 1 ) == '[' && preg_match ( '!^\[(.*?)\]!' , $ line , $ match ) ) { /* section found */ if ( substr ( $ match [ 1 ] , 0 , 1 ) == '.' ) { /* hidden section */ if ( $ this -> read_hidden ) { $ section_name = substr ( $ match [ 1 ] , 1 ) ; } else { /* break reference to $vars to ignore hidden section */ unset ( $ vars ) ; $ vars = array ( ) ; continue ; } } else { $ section_name = $ match [ 1 ] ; } if ( ! isset ( $ config_data [ 'sections' ] [ $ section_name ] ) ) $ config_data [ 'sections' ] [ $ section_name ] = array ( 'vars' => array ( ) ) ; $ vars = & $ config_data [ 'sections' ] [ $ section_name ] [ 'vars' ] ; continue ; } if ( preg_match ( '/^\s*(\.?\w+)\s*=\s*(.*)/s' , $ line , $ match ) ) { /* variable found */ $ var_name = rtrim ( $ match [ 1 ] ) ; if ( strpos ( $ match [ 2 ] , '"""' ) === 0 ) { /* handle multiline-value */ $ lines [ $ i ] = substr ( $ match [ 2 ] , 3 ) ; $ var_value = '' ; while ( $ i < $ count ) { if ( ( $ pos = strpos ( $ lines [ $ i ] , '"""' ) ) === false ) { $ var_value .= $ lines [ $ i ++ ] ; } else { /* end of multiline-value */ $ var_value .= substr ( $ lines [ $ i ] , 0 , $ pos ) ; break ; } } $ booleanize = false ; } else { /* handle simple value */ $ var_value = preg_replace ( '/^([\'"])(.*)\1$/' , '\2' , rtrim ( $ match [ 2 ] ) ) ; $ booleanize = $ this -> booleanize ; } $ this -> _set_config_var ( $ vars , $ var_name , $ var_value , $ booleanize ) ; } /* else unparsable line / means it is a comment / means ignore it */ } return $ config_data ; }
parse the source of a configuration file manually.

@param string $contents the file-contents to parse
parse the source of a configuration file manually .