Format URL.

@param string $url

@return string
11010
protected function formatUrl(string $url): string
    {
        $uri = $this->urlPrefix.$url;

        return $uri === '/' ? '/' : ltrim(rtrim($uri, '/'), '/');
    }
376841
protected function _validUrl($url) {
		$headers = Utility::getHeaderFromUrl($url);
		if ($headers === false) {
			return false;
		}
		$headers = implode("\n", $headers);
		$protocol = mb_strpos($url, 'https://') === 0 ? 'HTTP' : 'HTTP';
		if (!preg_match('#^' . $protocol . '/.*?\s+[(200|301|302)]+\s#i', $headers)) {
			return false;
		}
		if (preg_match('#^' . $protocol . '/.*?\s+[(404|999)]+\s#i', $headers)) {
			return false;
		}
		return true;
	}
655240
public static function getPathAndQueryFromUrl($url)
    {
        $parsedUrl = parse_url($url);
        $result = '';
        if (isset($parsedUrl['path'])) {
            if (substr($parsedUrl['path'], 0, 1) == '/') {
                $parsedUrl['path'] = substr($parsedUrl['path'], 1);
            }
            $result .= $parsedUrl['path'];
        }
        if (isset($parsedUrl['query'])) {
            $result .= '?' . $parsedUrl['query'];
        }
        return $result;
    }
300209
public function setUrl($url)
    {
        if (strpos($url, '/') !== 0) {
            $url = '/' . $url;
        }
        $this->url = $url;
        return $this;
    }
803643
public function webalizeUrl(string $url) : string
    {
        $regex = PageRepository::URL_REGEX;

        if (preg_match("/{$regex}/", $url) === FALSE)
        {
            throw new InvalidArgumentException('Url contains wrong characters. Allowed characters are \'a-z, 0-9, slash, dash\'');
        }

        $url = preg_replace('~-{2,}~', '-', $url);
        $url = preg_replace('~/{2,}~', '/', $url);
        $url = trim($url, '-/');

        return $url;
    }
1348129
private function parseUrl($url)
    {
        $parsed = parse_url($url);

        if ((count($parsed) === 1)
            && isset($parsed['path'])
            && (0 === strpos($parsed['path'], '?') || false !== strpos($parsed['path'], '&'))
        ) {
            $parsed = array(
                'query' => $parsed['path']
            );

            return $parsed;
        }

        return $parsed;
    }
1181737
protected function parseStringUrl(?string $url) : string
    {
        $parts = parse_url($url);

        if (isset($parts['query'])) {
            parse_str($parts['query'], $query);
        }

        return $this->create(
            $parts['scheme'] ?? null,
            $parts['host'] ?? null,
            $parts['path'] ?? null,
            $query ?? null,
            $parts['fragment'] ?? null,
            (Str::endsWith($url, '/')
                && (isset($parts['path'])
                    && ($parts['path'] !== '/' || !empty($parts['path']))) )
        );
    }
166196
public static function prepareUrl($url)
    {
        // $url = urlencode($url);

        $replacement = [
            '&' => '&amp;',
            "'" => '&apos;',
            '"' => '&quot;',
            '>' => '&gt;',
            '<' => '&lt;',
        ];

        $url = str_replace(array_keys($replacement), array_values($replacement), $url);

        return $url;
    }
681663
static public function formatUrl($url, $protocal=null)
	{
	    if (strpos($url, 'http') === false) {
	        $protocal || $protocal = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
	        if (!in_array($protocal, ['http', 'https'])) {
	            $protocal = 'http';
	        }
	        
	        $url = $protocal . '://' . $url;
	        $url = str_replace(["////", "///"], "//", $url);
	    }
	    
	    return rtrim($url, '/');
	}
117939
public function getRequestUrl($url)
    {
        if ($this->getPerPage() && $this->getPage()) {
            return $url . $this->getRequestPageInfo();
        }

        return $url;
    }
620258
public function transform( $url )
	{
		if( strncmp( $url, 'http', 4 ) !== 0 && strncmp( $url, 'data', 4 ) !== 0 ) {
			$url = $this->_baseurl . $url;
		}

		return $this->_enc->attr( $url );
	}
176118
private function cleanupUrl($url)
    {
        // rewrite part of urls to something more readable
        foreach ($this->config['rewrite_url'] as $find => $action) {
            if (false !== strpos($url, $find) && \is_array($action)) {
                $url = strtr($url, $action);
            }
        }

        // convert fragment to actual query parameters
        if ($fragmentPos = strpos($url, '#!')) {
            $fragment = parse_url($url, PHP_URL_FRAGMENT);
            // strip '!'
            $fragment = substr($fragment, 1);
            $query = ['_escaped_fragment_' => $fragment];

            // url without fragment
            $url = substr($url, 0, $fragmentPos);
            $url .= parse_url($url, PHP_URL_QUERY) ? '&' : '?';
            // needed for some sites
            $url .= str_replace('%2F', '/', http_build_query($query));
        }

        // remove fragment
        if ($pos = strpos($url, '#')) {
            $url = substr($url, 0, $pos);
        }

        return $url;
    }
1312558
public function parseUrl($url) {
		$url = parse_url($url);
		$url['vars'] = array();
		if (!isset($url['fragment'])) {
			$url['fragment'] = null;
		}
		if (isset($url['query'])) {
			parse_str($url['query'], $url['vars']);
		}

		return $url;
	}
958548
public function createFormUrl($url)
    {
        $urlParts = parse_url($url);

        $scheme = isset($urlParts['scheme']) ? $urlParts['scheme'] : '';
        $user = isset($urlParts['user']) ? $urlParts['user'] : '';
        $password = isset($urlParts['pass']) ? $urlParts['pass'] : '';
        $host = isset($urlParts['host']) ? $urlParts['host'] : '';
        $port = isset($urlParts['port']) ? $urlParts['port'] : null;
        $path = isset($urlParts['path']) ? $urlParts['path'] : '';
        $query = isset($urlParts['query']) ? $urlParts['query'] : '';
        $fragment = isset($urlParts['fragment']) ? $urlParts['fragment'] : '';

        $this->setUri($scheme, $host, $port, $path, $query, $fragment, $user, $password);

        return $this;
    }
663400
public static function prefaceURLwithHTTP($url) {
        $url = trim($url);

        if (substr($url, 0, 7 ) == "http://") {
            return $url;
        }

        if (substr($url, 0, 8 ) == "https://") {
            return $url;
        }

        return "http://".$url;
    }
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);
    }
475216
public function generateUrl($url)
    {
        $extern = false;
        if ((0 === strrpos($url, 'http://'))
            || (0 === strrpos($url, 'https://'))) {
            $extern = true;
        }

        $http = (isset($_SERVER['HTTPS'])) ? 'https://' : 'http://';

        if (!$extern) {
            return ($this->getRoot() == '/')
                ? (($this->getRoot() == $url) ? '' : $url) : $http.$_SERVER['SERVER_NAME'].$this->getRoot().$url;
        } else {
            return $url;
        }
    }