I have an application with a filenames a bit long.

I would like to remove the name of the file and extension of the php files and only show my domain or server name.
Example: this is what i have:
www.example.com/dir/my_long_file.php

This is what i need.

www.example.com

This code is for localhost:

$site_name  =   $_SERVER['REQUEST_URI'];
$site_name  =   explode('/', $site_name);
echo $site_name[1];

And this is for cloud server:

function get_root_domain(){
    $url    =   strtolower($_SERVER['HTTP_HOST']);
    $url    =   ereg_replace('www\.', '', $url);
    $url    =   parse_url($url);

    return (!empty($url['host'])) ? $url['host'] : $url['path'];
}

echo get_root_domain();

Thank you for the reply.
But the idea is not to get the host name. But to replace the browser information such that in the browser you can read only www.example.com.

Member Avatar for diafol

Is this what you need? how about bookmarking certain pages? If all pages share the same url?

This can be done with sessions, but it's a bit awkward. I may be wrong.

$url = $_SERVER['REQUEST_URI'];
$explode_url = explode('/', $site_name);
echo $explode_url[1];

Click Here

commented: copy of chayassongi's post +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.