Oihana PHP

isRelativePath.php

Table of Contents

Functions

isRelativePath()  : bool
Determines whether a given path is relative.

Functions

isRelativePath()

Determines whether a given path is relative.

isRelativePath(string $path) : bool

A path is considered relative if it is not absolute. This function is the direct inverse of isAbsolutePath(). It will return true for paths that do not start with a slash, a backslash, or a Windows drive letter.

Parameters
$path : string

The path to check.

Tags
see
isAbsolutePath()
example
// Relative paths (returns true)
var_dump( isRelativePath( 'documents/report.pdf' ) ) ; // true
var_dump( isRelativePath( '../images/pic.jpg'    ) ) ; // true
var_dump( isRelativePath( 'file.txt'             ) ) ; // true
var_dump( isRelativePath( ''                     ) ) ; // true (empty path)

// Absolute paths (returns false)
var_dump( isRelativePath( '/var/www'             ) ) ; // false
var_dump( isRelativePath( 'C:\\Users\\Test'      ) ) ; // false
var_dump( isRelativePath( 'D:/folder/'           ) ) ; // false
var_dump( isRelativePath( 'C:'                   ) ) ; // false
var_dump( isRelativePath( 'file:///c/Users/'     ) ) ; // false
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

True if the path is relative, false if it is absolute.


        
On this page

Search results