Backend Development 2 min read

PHP dirname() Function: Description, Parameters, Return Value, and Examples

The article explains PHP's dirname() function, detailing its purpose of returning the directory portion of a path, describing the $path parameter, the return values, and providing clear code examples demonstrating typical usage scenarios.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP dirname() Function: Description, Parameters, Return Value, and Examples

dirname() returns the directory part of a given path.

Explanation: When given a full file path string, the function removes the file name and returns the parent directory. If the path contains no directory separator, it returns a dot ('.') representing the current directory.

Parameter: $path – a string containing a path. Both forward slash (/) and backslash (\) are accepted as directory separators on Windows; on other systems only forward slash is used.

Return value: The parent directory of $path . If there is no slash, returns '.'; otherwise returns the string with the trailing '/' and the last component removed.

Examples:

backendPHPfunctionpathdirname
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.