function path_is_absolute( $path ) {}

Test if a give filesystem path is absolute (‘/foo/bar’, ‘c:\windows’).


  • string $path: File path

Return values

returns:True if path is absolute, false is not absolute.

Source code

function path_is_absolute( $path ) {

	// this is definitive if true but fails if $path does not exist or contains a symbolic link

	if ( realpath($path) == $path )

		return true;

	if ( strlen($path) == 0 || $path[0] == '.' )

		return false;

	// windows allows absolute paths like this

	if ( preg_match('#^[a-zA-Z]:\\\\#', $path) )

		return true;

	// a path starting with / or \ is absolute; anything else is relative

	return ( $path[0] == '/' || $path[0] == '\\' );



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: