dirname in PHP

Syntax of dirname in PHP

string dirname(string path)

Returns the directory component of path. This includes everything up to the filename portion (see basename) and doesn’t include the trailing path separator.

Example of dirname in PHP

<?php
dirname('.');    // Will return '.'.
dirname('/');    // Will return `\` on Windows and '/' on *nix systems.
dirname('\\');   // Will return `\` on Windows and '.' on *nix systems.
dirname('C:\\'); // Will return 'C:\' on Windows and '.' on *nix systems.
?>

Leave a Comment