What is the function basename() in PHP used for?
The function `basename()` in PHP is used to extract the filename from a given path. This can be useful when you have a full file path and only need the actual name of the file. The `basename()` function returns the base name of the file without the directory information.
// Example of using basename() function
$file_path = '/path/to/file.txt';
$file_name = basename($file_path);
echo $file_name; // Output: file.txt
Keywords
Related Questions
- What are the potential pitfalls of not initializing session_start() at the beginning of a PHP script when dealing with session variables?
- What are the potential pitfalls of using ORDER BY in PHP to retrieve numbers from a database?
- What are common mistakes to avoid when uploading files using PHP, especially when using FTP?