Getting File Name from Path using PHP
You may encounter scenarios where you need to extract the file name from a given path. PHP offers a convenient function for this task: basename().
Consider the following example where you want to retrieve the file name "Output.map" from the full path "F:Program FilesSSH Communications SecuritySSH Secure ShellOutput.map".
Using Basename
To accomplish this, you can utilize basename() as follows:
$path = "F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map"; $file = basename($path);
In this example, basename() will extract "Output.map" and assign it to the $file variable.
Additional Options
Basename() provides options to further customize the extraction process:
The above is the detailed content of How Can I Extract a Filename from a File Path Using PHP's `basename()` Function?. For more information, please follow other related articles on the PHP Chinese website!