/** * Normalizes the URL in a specified string and returns the new string. * * In a normalized URL string, the protocol is always indicated and always in lowercase, with "http" protocol being * the default one, the host part is always in lowercase too, a path is always present, with the default path being * "/", and the query string does not contain duplicate fields and "=" is added in the query string after any field * name that goes without a value and is not followed by "=". Also in a normalized URL string, only those * characters are percent-encoded for which it is required by the URL standard and hexadecimal letters in * percent-encoded characters appear in uppercase. For instance, "WWW.EXAMPLE.COM" is normalized to * "http://www.example.com/" and "HTTP: //www.example.com/path/to/some%3dite%6D" is normalized to * "http://www.example.com/path/to/some%3Ditem". * * Since fragment IDs in URLs are typically used to tell the browser the place to which the page needs to be * scrolled on the initial view, which is only a matter of presentation, it makes the comparison of URLs by their * normalized strings more consistent if fragment IDs are not taken into account. * * @param string $url The string with the URL to be normalized. * @param bool $keepFragmentId Tells whether the fragment ID, if the URL contains any, should be normalized too * and put into the normalized URL. * * @return CUStringObject A string with the normalized URL. */ public static function normalize($url, $keepFragmentId) { assert('is_cstring($url) && is_bool($keepFragmentId)', vs(isset($this), get_defined_vars())); $objUrl = new self($url); return !$keepFragmentId ? $objUrl->normalizedUrlWithoutFragmentId() : $objUrl->normalizedUrl(); }