What function can be used in PHP to extract the filename from a URL?
To extract the filename from a URL in PHP, you can use the `basename()` function. This function returns the trailing name component of the path, which in this case would be the filename. You can pass the URL as a parameter to the `basename()` function to extract just the filename.
$url = "https://www.example.com/path/to/file.txt";
$filename = basename($url);
echo $filename; // Output: file.txt
Related Questions
- What are some alternative approaches to securely handling prices and sensitive data in PHP forms and sessions?
- What potential issues or limitations should be considered when using file_exists or is_readable functions to check for file accessibility over a network in PHP?
- What considerations should be made when using the PHP mail function on a hosting service?