dirname
Description
The dirname of Filesystem for PHP returns a parent directory's path.
Syntax
dirname( string $path, int $levels = 1 ): string
Parameters
path
A path.
On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
levels
The number of parent directories to go up.
This must be an integer greater than 0.
Return
Returns the path of a parent directory. If there are no slashes in path, a dot ('.') is returned, indicating the current directory. Otherwise, the returned string is path with any trailing /component removed.
Examples
1 · path
<? echo dirname("/etc/passwd?a=1") . PHP_EOL; echo dirname("/etc/passwd") . PHP_EOL; echo dirname("/etc/?a=1") . PHP_EOL; echo dirname("/etc/") . PHP_EOL; echo dirname(".") . PHP_EOL; echo dirname("C:\\");
/etc /etc /etc / . .
2 · levels
<? $path = "/usr/local/lib"; echo dirname($path, 1) . PHP_EOL; echo dirname($path, 2) . PHP_EOL; echo dirname($path, 3);
/usr/local /usr /
Links
Filesystem
- basename
- chgrp
- chmod
- chown
- clearstatcache
- copy
- disk_free_space
- disk_total_space
- diskfreespace
- fclose
- feof
- fflush
- fgetc
- fgetcsv
- fgets
- file
- file_exists
- file_get_contents
- file_put_contents
- fileatime
- filectime
- filegroup
- fileinode
- filemtime
- fileowner
- fileperms
- filesize
- filetype
- flock
- fnmatch
- fopen
- fpassthru
- fputcsv
- fputs
- fread
- fscanf
- fseek
- fstat
- ftell
- ftruncate
- fwrite
- glob
- is_dir
- is_executable
- is_file
- is_link
- is_readable
- is_uploaded_file
- is_writable
- is_writeable
- lchgrp
- lchown
- link
- linkinfo
- lstat
- mkdir
- move_uploaded_file
- pathinfo
- pclose
- popen
- readfile
- readlink
- realpath
- realpath_cache_get
- realpath_cache_size
- rename
- rewind
- rmdir
- set_file_buffer
- stat
- symlink
- tempnam
- tmpfile
- touch
- umask
- unlink