Rebuild a URL with known search parameters

@param string $url

@return string
779224
static function addSearchParamsToUrl( $url ) {

		if ( ! empty( $_REQUEST['s'] ) ) {
			$url = esc_url( add_query_arg( 's', $_REQUEST['s'], $url ) );
		}

		if ( ! empty( $_REQUEST['orderby'] ) ) {
			$url = esc_url( add_query_arg( 'orderby', $_REQUEST['orderby'], $url ) );
		}

		if ( ! empty( $_REQUEST['order'] ) ) {
			$url = esc_url( add_query_arg( 'order', $_REQUEST['order'], $url ) );
		}

		if ( ! empty( $_REQUEST['paged'] ) ) {
			$url = esc_url( add_query_arg( 'paged', $_REQUEST['paged'], $url ) );
		}

		return $url;
	}
311770
protected function formatUrl($url)
    {
        $uri = !is_null($this->prefixUrl) ? $this->prefixUrl . $url : $url;

        return $uri == '/' ? '/' : ltrim(rtrim($uri, '/'), '/');
    }
512712
public function convertUrl(string $url): string
    {
        $parsed = parse_url($url);
        if ($parsed === false) {
            throw new InvalidArgumentException('The given string does not look like a URL', 206);
        }

        // Nothing to do
        if ($parsed['host'] === null) {
            return $url;
        }
        $parsed['host'] = $this->convert($parsed['host']);

        return http_build_url($parsed);
    }
311705
public function sanitize($url)
    {
        try {
            $url = Router::url($url);
        } catch (\Exception $ex) {
            return '';
        }

        if (!str_starts_with($url, '/')) {
            return $url;
        }

        if (str_starts_with($url, $this->baseUrl())) {
            $url = str_replace_once($this->baseUrl(), '', $url);
        }

        return $this->localePrefix($url);
    }
21711
private function getUrl($url)
    {
        // Check for URL scheme
        if (parse_url($url, PHP_URL_SCHEME) === null) {
            $url = Arr::get($this->config, 'base_uri') . $url;
        }

        return $url;
    }
99661
public static function params($url) {
        $path  = explode('?', $url)[0];
        $query = parse_url($url, PHP_URL_QUERY);
        if ($query) {
            return site_url($path, $query);
        } else {
            return false;
        }
    }
279918
public function match($url) {
		// Remove the start and end slash of URL
		$url = trim($url, '/');
		// Replace path parameters (:parameter) by
		$path = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], $this->path);
		// Define the regex patterb with the new path after replaced the parameters of path
		$regex = "#^$path$#i";

		// Check if the url matchs the path
		if (!preg_match($regex, $url, $matches)) {
			return false;
		}

		// Keep only the parameters
		array_shift($matches);

		return $matches;
	}
359604
protected function extractUrlParameters($url)
    {
        $query = parse_url($url, PHP_URL_QUERY);
        parse_str($query, $params);

        return $params;
    }
398132
public function resolveUrl($url) {
		// If the URL is seriously malformed it’s probably beyond the scope of this
		// parser to try to do anything with it.
		if (parse_url($url) === false) {
			return $url;
		}

		// per issue #40 valid URLs could have a space on either side
		$url = trim($url);

		$scheme = parse_url($url, PHP_URL_SCHEME);

		if (empty($scheme) and !empty($this->baseurl)) {
			return resolveUrl($this->baseurl, $url);
		} else {
			return $url;
		}
	}
1048845
public static function url2source($url) {

        $mappingRules = array();
        foreach ( self::$urlMappingRules as $target => $source ) {
            $mappingRules['/' . $target . '/iU'] = $source;
        }
        return preg_replace(array_keys($mappingRules), $mappingRules, $url);

    }
81774
private function getUrl(string $url): string
    {
        $urlParts = parse_url($url);

        if ($urlParts === false) {
            throw new \ParseError("Could not parse URL: $url");
        }

        if ($this->baseUrl !== null && ! isset($urlParts['host'])) {
            $url = $this->baseUrl . '/' . ltrim($url, '/');
        }

        return $url;
    }
521995
public static function parse_URL($url)
	{
		$params = parse_url($url);
		$params['extras'] = array();
		if (isset($params['query']))
		{
			parse_str($params['query'], $params['extras']);
		}
		return $params;
	}
725985
private function getRequest($url) {
    $part = parse_url($url);

    if(isset($part['query'])) {
      parse_str($part['query'], $query);
      if(isset($query[$this->getParam])) {
        unset($query[$this->getParam]);
      }
      if(sizeof($query) > 0) {
        $request = $part['path'].http_build_query($query);
      } else {
        $request = $part['path'];
      }
    } else {
      $request = $part['path'];
    }

    return $request;
  }
1238512
protected function _autoCompleteUrl($url) {
		if (mb_strpos($url, '/') === 0) {
			$url = Router::url($url, true);
		} elseif (mb_strpos($url, '://') === false && mb_strpos($url, 'www.') === 0) {
			$url = 'http://' . $url;
		}
		return $url;
	}
434572
public static function google(Url $url)
    {
        if (($value = $url->getQueryParameter('url'))) {
            return Url::create($value);
        }

        return $url;
    }
466730
public static function normalizeUrl($url)
    {
        foreach (self::$urlPrefixMap as $prefix => $id) {
            if (strtolower(substr($url, 0, strlen($prefix))) == $prefix) {
                return array(
                    'url'      => substr($url, strlen($prefix)),
                    'prefixId' => $id
                );
            }
        }

        return array('url' => $url, 'prefixId' => null);
    }
877493
protected function cleanUrl($url)
    {
        $parts = parse_url($url);
        $fragment = empty($parts['fragment']) ? '' : '#'.$parts['fragment'];
        $path = empty($parts['path']) ? '/' : $parts['path'];

        return preg_replace('/^\/[^\.\/]+\.php\//', '/', $path).$fragment;
    }