path_is_absolute

Test if a give filesystem path is absolute.

Description

path_is_absolute( (string) $path ); 

For example, /foo/bar,, or c:\windows..

Parameters (1)

0. $path (string)
File path.

Usage

  1. if ( !function_exists( 'path_is_absolute' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // File path. 
  5. $path = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = path_is_absolute($path); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function path_is_absolute( $path ) { 
  2. /** 
  3. * This is definitive if true but fails if $path does not exist or contains 
  4. * a symbolic link. 
  5. */ 
  6. if ( realpath($path) == $path ) 
  7. return true; 
  8.  
  9. if ( strlen($path) == 0 || $path[0] == '.' ) 
  10. return false; 
  11.  
  12. // Windows allows absolute paths like this. 
  13. if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) 
  14. return true; 
  15.  
  16. // A path starting with / or \ is absolute; anything else is relative. 
  17. return ( $path[0] == '/' || $path[0] == '\\' );