+

PHP dirname () function

The dirname() function returns the path to the parent directory, which includes a period (`. `) unless the path contains a forward slash indicating the current directory.Syntax:
string dirname ($path)
Parameters:The dirname() function in PHP only takes one parameter, which is $path. This parameter specifies the path to check.Return value:returns the path to the parent directory.Errors and exceptions :
  • When specifying a path, both forward slashes, forward slashes (/) and backslashes (/) are used as a directory separator character in Windows environment, whereas in other environments it is just forward slash (/) .
  • The dirname() function operates on an input string and therefore does not know about the actual filesystem or path components such as "..".
  • Examples :
    Input: dirname ("user01 / engineerforengineer / gfg.txt") Output: user01 / engineerforengineer Input: dirname ("/ engineerforengineer / gfg.txt"); Output: / engineerforengineer
    The programs below illustrate the dirname() function:Program 1 :  
    // specifying the path to the function dirname() echo dirname ( " user01 / engineerforengineer / gfg.txt " )  
    ?>
    Output:
    user01 / engineerforengineer
    Program 2 :  
    // specifying the path to the dirname() function echo dirname ( " / engineerforengineer / gfg.txt " );  
    ?>
    Output:
    / engineerforengineer < / pre> Link:
    http://php.net/manual /en/function.dirname.php
    Get Solution for free from DataCamp guru