コード例 #1
0
  function clean_path($path, $to_type=DIR_SEPARATOR_LOCAL)
  {
    $path = fs :: convert_separators($path, $to_type);
    $separator = fs :: separator($to_type);
		
		$path = fs :: _normalize_separators($path, $separator);
		        
    $path_elements= explode($separator, $path);
    $newpath_elements= array();
    
    foreach ($path_elements as $path_element)
    {
      if ( $path_element == '.' )
      	continue;
      if ( $path_element == '..' &&
           count( $newpath_elements) > 0 )
      	array_pop( $newpath_elements);
      else
      	$newpath_elements[] = $path_element;
    }
    if ( count( $newpath_elements) == 0 )
    	$newpath_elements[] = '.';
    	
    $path = implode($separator, $newpath_elements);
    return $path;
  }