src/Path.php
public static function clean($path, $ds=DIRECTORY_SEPARATOR)
  {
    if ( !is_string($path) && !empty($path) ){
      return '';
      throw new Exception('Path::clean: $path is not a string or is empty.');
    }
    
    $path = trim($path);
    
    if ( empty($path) ){
      $path = self::$ROOT_PATH;
    }
    
    // Remove double slashes and backslashes and convert all slashes and backslashes to DIRECTORY_SEPARATOR
    // If dealing with a UNC path don't forget to prepend the path with a backslash.
    elseif ( $ds == '\\' && $path[0] == '\\' && $path[1] == '\\' ){
      $path = "\\" . preg_replace('#[/\\\\]+#', $ds, $path);
    }
    else {
      $path = preg_replace('#[/\\\\]+#', $ds, $path);
    }

    return $path;
  }
public static function clean($path, $ds=DIRECTORY_SEPARATOR)
  {
    if ( !is_string($path) && !empty($path) ){
      return '';
      throw new Exception('Path::clean: $path is not a string or is empty.');
    }
    
    $path = trim($path);
    
    if ( empty($path) ){
      $path = self::$ROOT_PATH;
    }
    
    // Remove double slashes and backslashes and convert all slashes and backslashes to DIRECTORY_SEPARATOR
    // If dealing with a UNC path don't forget to prepend the path with a backslash.
    elseif ( $ds == '\\' && $path[0] == '\\' && $path[1] == '\\' ){
      $path = "\\" . preg_replace('#[/\\\\]+#', $ds, $path);
    }
    else {
      $path = preg_replace('#[/\\\\]+#', $ds, $path);
    }

    return $path;
  }
public static function clean ( $ path , $ ds = DIRECTORY_SEPARATOR ) { if ( ! is_string ( $ path ) && ! empty ( $ path ) ) { return '' ; throw new Exception ( 'Path::clean: $path is not a string or is empty.' ) ; } $ path = trim ( $ path ) ; if ( empty ( $ path ) ) { $ path = self :: $ ROOT_PATH ; } // Remove double slashes and backslashes and convert all slashes and backslashes to DIRECTORY_SEPARATOR // If dealing with a UNC path don't forget to prepend the path with a backslash. elseif ( $ ds == '\\' && $ path [ 0 ] == '\\' && $ path [ 1 ] == '\\' ) { $ path = "\\" . preg_replace ( '#[/\\\\]+#' , $ ds , $ path ) ; } else { $ path = preg_replace ( '#[/\\\\]+#' , $ ds , $ path ) ; } return $ path ; }
Function to strip additional / or \ in a path name.

@param   string  $path  The path to clean.
@param   string  $ds    Directory separator (optional).
@return   string  The cleaned path
@throws   Exception
Function to strip additional / or \ in a path name .