php dirname

dirname in php may not be what you think it to be: given a full path name of a file, return its directory part. In fact, dirname(pathname) returns the parent directory of the parameter, wether it is a file or a directory, i.e.

dirname("C:\\dir\\file.txt") returns C:\dir,

dirname("C:\\dir") returns C:\, NOT C:\dir,

dirname("C:\\dir\\")  also returns C:\ ,

note that,

dirname("C:\\") returns  C:\

dirname("C:") returns C:

i.e., the dirname of root is the drive name. dirname("C") returns .(“C” is considered as a file under the current folder which is denoted by .)

Posted in

Leave a Reply