How can PHP be used to extract only the file name from a REQUEST_URI that includes query parameters?
To extract only the file name from a REQUEST_URI that includes query parameters, you can use the basename() function in PHP. This function will return the last component of the path, which in this case is the file name. By using this function, you can easily extract just the file name from the REQUEST_URI and ignore any query parameters.
// Get the REQUEST_URI
$request_uri = $_SERVER['REQUEST_URI'];
// Extract the file name from the REQUEST_URI
$file_name = basename(parse_url($request_uri, PHP_URL_PATH));
echo $file_name;
Keywords
Related Questions
- What is the best way to implement a REHASH function in a multiuser socket server script without disconnecting users?
- How can PHP frameworks or libraries simplify the process of working with SQL databases?
- What is the recommended method in PHP to filter user input to only allow digits and a comma before saving to a database?