/** * Returns all values in a certain category and supports multiple appereances. * * @param string $key * @param string $category * @param string $string * @return array */ public static function parseValuesByCategory($key, $category, $string) { if (!$key || !$string || !$category) { return array(); } $string = ParseINI::normalize($string); if (strpos($string, $key) === false || strpos($string, '[' . $category . ']') === false) { return array(); } $values = array(); $lines = explode("\n", $string); $current_category = ''; foreach ($lines as $line) { $line = trim($line); if (strpos($line, '[') !== false && strpos($line, ']') !== false && strpos($line, '=') === false) { $start = strpos($line, '[') + 1; $end = strpos($line, ']') - 1; $current_category = substr($line, $start, $end); } if ($current_category != $category) { continue; } //wrong category if (strpos($line, ';') === 0) { continue; } //comment if (strpos($line, $key) === false) { continue; } //not needed $values[] = ParseINI::parseValue($key, $line); } return $values; }