repeats = $repeats; $this->list = array(); /* GET */ $this->load($_SERVER['QUERY_STRING']); /* POST */ $this->load(file_get_contents('php://input')); } public $repeats; public $list; public function get($name, $value = null) { if (array_key_exists($name, $this->list)) $value = $this->list[$name]; return $value; } public function has($name) { return array_key_exists($name, $this->list); } public function remove($name, $value = null) { if (array_key_exists($name, $this->list)) { $value = $this->list[$name]; unset($this->list[$name]); } return $value; } private function load($string) { if ($string == '') return; foreach (explode('&', $string) as $pair) { $pair = explode('=', $pair); $name = urldecode($pair[0]); $value = urldecode($pair[1]); switch ($this->repeats) { case self::REPEATS_AS_NEEDED: if (! array_key_exists($name, $this->list)) $this->list[$name] = $value; else if (! is_array($this->list[$name])) $this->list[$name] = array($this->list[$name], $value); else $this->list[$name][] = $value; break; case self::REPEATS_ALWAYS: $this->list[$name][] = $value; break; case self::REPEATS_NEVER: default: $this->list[$name] = $value; break; } } } } ?>