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.
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)Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.