GET THE PAGE NAME FROM THE URL

Code (THERE IS NO DISPLAY FOR THE PAGE)

<?php
//get the url using the "server" command
$page= $_SERVER['REQUEST_URI'];

//separate the url into an array by splitting the address by the forward slash
$page = explode("/", $page);
//get the number of elements in the array and subtract by one to get the page name
$page_count= count($page)-1;

//set a variable for the page name
$page2= $page[$page_count]; //if the array is empty, the page is index.php. Reset the variable to index.php if($page2=='')
{
$page2= "index.php";
}

//remove any variables in the url by splitting into another array using the "?" $pagename= explode("?", $page2); //the page name will by the first element of the array $pagename= $pagename[0]; ?>