public static function normalizeUrl($url, $rtrim = true){
		$url = trim($url);
		// replace every back slash with forward slash
		$url = str_replace('\\', '/', $url);
		// replace all double slashes with single
		$url  = preg_replace( '/\/+/', '==DS==', $url );
		// trim slashes on begining
		$segments = explode('==DS==', $url);
		$url = implode('/', $segments);
		//$url = ltrim($url, '/');
		if($rtrim){
			$url = rtrim($url, '/');
		}
		return $url;
	}
public static function normalizeUrl($url, $rtrim = true){
		$url = trim($url);
		// replace every back slash with forward slash
		$url = str_replace('\\', '/', $url);
		// replace all double slashes with single
		$url  = preg_replace( '/\/+/', '==DS==', $url );
		// trim slashes on begining
		$segments = explode('==DS==', $url);
		$url = implode('/', $segments);
		//$url = ltrim($url, '/');
		if($rtrim){
			$url = rtrim($url, '/');
		}
		return $url;
	}
public static function normalizeUrl ( $ url , $ rtrim = true ) { $ url = trim ( $ url ) ; // replace every back slash with forward slash $ url = str_replace ( '\\' , '/' , $ url ) ; // replace all double slashes with single $ url = preg_replace ( '/\/+/' , '==DS==' , $ url ) ; // trim slashes on begining $ segments = explode ( '==DS==' , $ url ) ; $ url = implode ( '/' , $ segments ) ; //$url = ltrim($url, '/'); if ( $ rtrim ) { $ url = rtrim ( $ url , '/' ) ; } return $ url ; }
Normalizes url slashes when mixed between path and url conversion

It takes string with mixed or doubled slashes and converts them
to single forward slashes, and optionally trims right slash

There are two parameters,
string that will be normalized and optional rtrim flag

@param string $url - string to be normalized
@param boolean $rtrim - flag for right trim option
@return string normalized url.
Normalizes url slashes when mixed between path and url conversion