Backend Development 2 min read

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

The PHP basename() function returns the filename component of a given path, optionally removing a specified suffix, and the article explains its parameters, return value, and provides multiple code examples with expected output.

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

The basename() function in PHP returns the base name of a given path, optionally removing a specified suffix.

Parameters

path : The full path to a file; both forward (/) and backslashes (\) are accepted on Windows, while only forward slashes are used on other systems.

suffix (optional): If the filename ends with this suffix, it will be stripped from the result.

Return value

Returns the base name component of $path as a string.

Example

Output:

1) sudoers
2) passwd
3) etc
4) .
5)
BackendPHPfunctionfile pathbasename
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.