How can the basename() function in PHP be used to extract the current page name from a URL?

To extract the current page name from a URL in PHP, you can use the basename() function along with the $_SERVER['REQUEST_URI'] variable. The basename() function returns the base name of a file path, which in this case will be the current page name from the URL. By passing the $_SERVER['REQUEST_URI'] variable to the basename() function, you can extract the current page name.

$url = $_SERVER['REQUEST_URI'];
$pageName = basename($url);
echo $pageName;