find the parent directory of a directory in php

To find the parent directory of a directory in PHP, you can use the dirname() function which returns the parent directory of a directory.

Here's an example:

main.php
$dir_path = '/path/to/directory';
$parent_dir = dirname($dir_path);

echo $parent_dir; // Output: /path/to
107 chars
5 lines

In the example above, the $dir_path variable holds the path of the directory for which we want to find the parent directory. The dirname() function takes this path as an argument and returns the parent directory path which is stored in $parent_dir variable. Finally, we print the parent directory path using echo statement.

I hope this helps!

gistlibby LogSnag