public function removeDotSegments(string $path): string
	{
		if (empty($path) || $path === '/')
		{
			return $path;
		}

		$output = [];

		$input = explode('/', $path);

		if (empty($input[0]))
		{
			unset($input[0]);
			$input = array_values($input);
		}

		// This is not a perfect representation of the
		// RFC, but matches most cases and is pretty
		// much what Guzzle uses. Should be good enough
		// for almost every real use case.
		foreach ($input as $segment)
		{
			if ($segment === '..')
			{
				array_pop($output);
			}
			else if ($segment !== '.' && $segment !== '')
			{
				array_push($output, $segment);
			}
		}

		$output = implode('/', $output);
		$output = ltrim($output, '/ ');

		if ($output !== '/')
		{
			// Add leading slash if necessary
			if (strpos($path, '/') === 0)
			{
				$output = '/' . $output;
			}

			// Add trailing slash if necessary
			if (substr($path, -1, 1) === '/')
			{
				$output .= '/';
			}
		}

		return $output;
	}
public function removeDotSegments(string $path): string
	{
		if (empty($path) || $path === '/')
		{
			return $path;
		}

		$output = [];

		$input = explode('/', $path);

		if (empty($input[0]))
		{
			unset($input[0]);
			$input = array_values($input);
		}

		// This is not a perfect representation of the
		// RFC, but matches most cases and is pretty
		// much what Guzzle uses. Should be good enough
		// for almost every real use case.
		foreach ($input as $segment)
		{
			if ($segment === '..')
			{
				array_pop($output);
			}
			else if ($segment !== '.' && $segment !== '')
			{
				array_push($output, $segment);
			}
		}

		$output = implode('/', $output);
		$output = ltrim($output, '/ ');

		if ($output !== '/')
		{
			// Add leading slash if necessary
			if (strpos($path, '/') === 0)
			{
				$output = '/' . $output;
			}

			// Add trailing slash if necessary
			if (substr($path, -1, 1) === '/')
			{
				$output .= '/';
			}
		}

		return $output;
	}
public function removeDotSegments ( string $ path ) : string { if ( empty ( $ path ) || $ path === '/' ) { return $ path ; } $ output = [ ] ; $ input = explode ( '/' , $ path ) ; if ( empty ( $ input [ 0 ] ) ) { unset ( $ input [ 0 ] ) ; $ input = array_values ( $ input ) ; } // This is not a perfect representation of the // RFC, but matches most cases and is pretty // much what Guzzle uses. Should be good enough // for almost every real use case. foreach ( $ input as $ segment ) { if ( $ segment === '..' ) { array_pop ( $ output ) ; } else if ( $ segment !== '.' && $ segment !== '' ) { array_push ( $ output , $ segment ) ; } } $ output = implode ( '/' , $ output ) ; $ output = ltrim ( $ output , '/ ' ) ; if ( $ output !== '/' ) { // Add leading slash if necessary if ( strpos ( $ path , '/' ) === 0 ) { $ output = '/' . $ output ; } // Add trailing slash if necessary if ( substr ( $ path , - 1 , 1 ) === '/' ) { $ output .= '/' ; } } return $ output ; }
Used when resolving and merging paths to correctly interpret and
remove single and double dot segments from the path per
RFC 3986 Section 5.2.4

@see http://tools.ietf.org/html/rfc3986#section-5.2.4

@param string $path

@return   string
@internal param \CodeIgniter\HTTP\URI $uri
Used when resolving and merging paths to correctly interpret and remove single and double dot segments from the path per RFC 3986 Section 5 . 2 . 4