PHP: Extracting File Names from Complete Paths
Obtaining the file name alone from a full file path is a common task when working with file systems. In PHP, this can be accomplished using the basename() function.
Example:
Consider the following file path:
F:\Program Files\SSH Communications Security\SSH Secure Shell\Output.map
Objective: Extract the file name "Output.map" from the path.
Solution:
The basename() function takes a file path as an input and returns the file name. The following code snippet demonstrates its usage:
$path = "F:/Program Files/SSH Communications Security/SSH Secure Shell/Output.map"; $filename = basename($path); echo $filename; // Output: Output.map
Additional Notes:
$filename = basename($path, ".map"); // Output: Output
The above is the detailed content of How Can I Extract a Filename from a Full File Path in PHP?. For more information, please follow other related articles on the PHP Chinese website!