Basename in PHP | PHP basename() Function

Introduction

PHP has a function called basename that helps to fetch the filename present at the specified path. The function returns and prints the filename or the directory path passed in arguments. The procedure also displays the script name if the basename used is $0.  Programmers use this function to check the files present at the specified location or use the program flow filenames.

Hence, the programmers use the basename function in PHP to find the files present at any location and get them printed on the console. The basename function is like any other built-in function or user-defined function in  PHP, such as string functions, math functions, numeric functions, date functions, and many more.

Basename Function in PHP

The basename is an in-built function in PHP, which returns the file name present at the path provided as an argument.

Syntax:

Below is the syntax to use the Basename function in PHP.

String basename($path, $suffix)

The function has two parameters, i.e., path and suffix.

  • $path: Path is a mandatory parameter and s of String type. This parameter specifies the path at which the file is to locate.
  • $suffix: Suffix is an optional parameter that hides the file extension if the file has a suffix.

The function returns the file basename, which is present at the path passed as $path in the basename parameter.

#full stack development #basename in php #php #php basename

Basename in PHP | PHP basename() Function