Oihana PHP

isAbsolutePath.php

Table of Contents

Functions

isAbsolutePath()  : bool
Determines whether a given path is absolute.

Functions

isAbsolutePath()

Determines whether a given path is absolute.

isAbsolutePath(string $path) : bool

This function checks for both UNIX-style absolute paths (starting with "/") and Windows-style absolute paths (e.g., "C:", "C:/", or just "C:"). It also handles paths with URI schemes like "file://" by stripping the scheme before analysis.

Parameters
$path : string

The path to check.

Tags
example

Unix-style paths

isAbsolutePath('/var/www'); // true

Windows-style paths

isAbsolutePath('C:\\Users\\Test'); // true
isAbsolutePath('D:/folder/file.txt'); // true
isAbsolutePath('C:'); // true
isAbsolutePath('\\network-share\folder'); // true

Paths with schemes

isAbsolutePath('file:///c/Users/'); // true

Relative paths

isAbsolutePath('documents/report.pdf'); // false
isAbsolutePath('../images/pic.jpg'); // false
isAbsolutePath('file.txt'); // false

Edge cases

isAbsolutePath(''); // false
isAbsolutePath('/'); // true
isAbsolutePath('C:/'); // true
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

True if the path is absolute, false otherwise.


        
On this page

Search results