", $url)) return false; //Then split the URL $path = strstr($url, "://"); $path = str_replace("://", "", $path); //Check if we are at the root of the domain or not if(!preg_match("", $path)) return $path; //Else the url is a little more complex return explode("/", $path)[0]; }