Advertisements

path_is_absolute

Definition:
function path_is_absolute( $path ) {}

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

Parameters

  • 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] == '\\' );

}

2485

Advertisements

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:

WordPress.com Logo

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

Google+ photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: