All pastes #424539 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-04-04 21:11 UTC
rendered paste body
function getIndexTag($patern, $filename) {
	$f = get_file_utf8($filename);
	
	if (trim($f[0]) <> $patern) return "invalid patern";
	
	$f[0] = "";
	
	while(list($key, $line) = each($f)) {
		$line = trim($line);
		if (substr($line, 0, 1) == "[") {
			$file = trim(substr($line, 1, -1));
			$base[$file] = array();
		}	
		else if (ereg("^#", $line))
			echo "\n".$line;
			
		else if ($line <> '') {
			list($field, $value) = explode("=", $line);
			$field = trim($field);
			$value = trim($value);
			$base[$file][$field] = $value;
		}

	}
	return $base;
}



example: 
$src = "myindex.txt";
print_r(getIndexTag("\\Swac_Index_Tags", $src));