src/Wikimedia/RelPath.php
public static function splitPath( $path ) {
		$fragments = [];

		while ( true ) {
			$cur = dirname( $path );
			if ( $cur[0] === DIRECTORY_SEPARATOR ) {
				// dirname() on Windows sometimes returns a leading backslash, but other
				// times retains the leading forward slash. Slashes other than the leading one
				// are returned as-is, and therefore do not need to be touched.
				// Furthermore, don't break on *nix where \ is allowed in file/directory names.
				$cur[0] = '/';
			}

			if ( $cur === $path || ( $cur === '.' && basename( $path ) === $path ) ) {
				break;
			}

			$fragment = trim( substr( $path, strlen( $cur ) ), '/' );

			if ( !$fragments ) {
				$fragments[] = $fragment;
			} elseif ( $fragment === '..' && basename( $cur ) !== '..' ) {
				$cur = dirname( $cur );
			} elseif ( $fragment !== '.' ) {
				$fragments[] = $fragment;
			}

			$path = $cur;
		}

		if ( $path !== '' ) {
			$fragments[] = trim( $path, '/' );
		}

		return array_reverse( $fragments );
	}
public static function splitPath( $path ) {
		$fragments = [];

		while ( true ) {
			$cur = dirname( $path );
			if ( $cur[0] === DIRECTORY_SEPARATOR ) {
				// dirname() on Windows sometimes returns a leading backslash, but other
				// times retains the leading forward slash. Slashes other than the leading one
				// are returned as-is, and therefore do not need to be touched.
				// Furthermore, don't break on *nix where \ is allowed in file/directory names.
				$cur[0] = '/';
			}

			if ( $cur === $path || ( $cur === '.' && basename( $path ) === $path ) ) {
				break;
			}

			$fragment = trim( substr( $path, strlen( $cur ) ), '/' );

			if ( !$fragments ) {
				$fragments[] = $fragment;
			} elseif ( $fragment === '..' && basename( $cur ) !== '..' ) {
				$cur = dirname( $cur );
			} elseif ( $fragment !== '.' ) {
				$fragments[] = $fragment;
			}

			$path = $cur;
		}

		if ( $path !== '' ) {
			$fragments[] = trim( $path, '/' );
		}

		return array_reverse( $fragments );
	}
public static function splitPath ( $ path ) { $ fragments = [ ] ; while ( true ) { $ cur = dirname ( $ path ) ; if ( $ cur [ 0 ] === DIRECTORY_SEPARATOR ) { // dirname() on Windows sometimes returns a leading backslash, but other // times retains the leading forward slash. Slashes other than the leading one // are returned as-is, and therefore do not need to be touched. // Furthermore, don't break on *nix where \ is allowed in file/directory names. $ cur [ 0 ] = '/' ; } if ( $ cur === $ path || ( $ cur === '.' && basename ( $ path ) === $ path ) ) { break ; } $ fragment = trim ( substr ( $ path , strlen ( $ cur ) ) , '/' ) ; if ( ! $ fragments ) { $ fragments [ ] = $ fragment ; } elseif ( $ fragment === '..' && basename ( $ cur ) !== '..' ) { $ cur = dirname ( $ cur ) ; } elseif ( $ fragment !== '.' ) { $ fragments [ ] = $ fragment ; } $ path = $ cur ; } if ( $ path !== '' ) { $ fragments [ ] = trim ( $ path , '/' ) ; } return array_reverse ( $ fragments ) ; }
Split a path into path components.

@param string $path File path.
@return array Array of path components.
Split a path into path components .