<?
function parse_keywords($Query, $Explicit = false){
	$Query = trim($Query);
	if (!$Query) return null;
	if (!preg_match('/\s/', $Query)) return array($Query);

	$Query = preg_replace('/\s+/', ' ', $Query);

	$inQuotes = false;
	for ($i = 0; $i < strlen($Query); $i++){
		$prev = $chr;
		$chr = $Query[$i];

		if ($chr == ' ' && $word && !$inQuotes){
			$words[] = $word;
			$word = '';
			continue;
		}
		if ($chr == '"' && $prev != '\"'){
			$inQuotes = (!$inQuotes);
			continue;
		}

		$word .= $chr;
	}
	if ($word) $words[] = $word;

	if ($Explicit){
		foreach ($words as $k=>$word){
			$found = false;
			foreach (array('+', '-', '<', '>', '~', '*') as $Operator)
				if (substr($word, 0, 1) == $Operator) $found = true;

			if (!$found)
				$words[$k] = '+' . $word;
		}
	}

	foreach ($words as $k=>$word) $words[$k] = '"' . $word . '"';
	return $words;
}
?>
