public static function parse($contents)
{
$servers = array();
$lines = explode("\n", $contents);
$key = null;
foreach ($lines as $line) {
$line = trim($line);
if (preg_match("/^(#?)[\\s\t]*([^#\\s\t=]+)[\\s\t=]+(.*)\$/", $line, $matches)) {
if ($matches && count($matches) != 4) {
continue;
}
$isComment = $matches[1] == "#";
$first = $matches[2];
$second = $matches[3];
// Check for special comment key/value pairs
if ($isComment && $key && strpos($first, "altax.") !== false) {
$servers[$key][$first] = $second;
}
// Ignore commented line.
if ($isComment) {
continue;
}
if ($first == "Host") {
// a new host section
$key = $second;
$servers[$key] = array();
}
$servers[$key][strtolower($first)] = $second;
}
}
return $servers;
}