parts = parse_url($url); } /** * Returns a string representation of this URL */ public function __toString() { return unparse_url($this->parts); } /** * Removes undesired query parameters */ protected function cleanupQuery() { if (! isset($this->parts['query'])) { return; } $queryParams = explode('&', $this->parts['query']); foreach (self::$annoyingQueryParams as $annoying) { foreach ($queryParams as $param) { if (startsWith($param, $annoying)) { $queryParams = array_diff($queryParams, array($param)); continue; } } } if (count($queryParams) == 0) { unset($this->parts['query']); return; } $this->parts['query'] = implode('&', $queryParams); } /** * Removes undesired fragments */ protected function cleanupFragment() { if (! isset($this->parts['fragment'])) { return; } foreach (self::$annoyingFragments as $annoying) { if (startsWith($this->parts['fragment'], $annoying)) { unset($this->parts['fragment']); break; } } } /** * Removes undesired query parameters and fragments * * @return string the string representation of this URL after cleanup */ public function cleanup() { $this->cleanupQuery(); $this->cleanupFragment(); return $this->__toString(); } }