Remove URI from a link with php (http://misitio.com/uri/uri/loquesea)

0

I would like to delete the URI, that is to say what follows from a URL, as in the example in the title of the question with PHP.

http://misitio.com/uri/uri/loquesea - > http://misitio.com

@ RobertoLeónOramas I am requesting a php sanitizer, not a rewrite htaccess rule.

@MrViKxD Returns the hostname in which the site is accessed, I need a sanitizer, that's not what I need.

    
asked by Francisco Villalobo 08.04.2017 в 22:36
source

3 answers

0

You can use the array $ _SERVER

$_SERVER['SERVER_ADDR'];
    
answered by 08.04.2017 в 22:49
0
$url = explode('/', $url);
$url = implode('/', array_slice($url, 0, 3));
    
answered by 08.04.2017 в 23:37
0

If you want to extract the current domain, it would suffice:

    $host = $_SERVER['HTTP_HOST']; //HTTP_HOST devuelve el dominio.com o www.dominio.com
    $host = 'http://'.$host //Si quieres añadir http

If what you want is a function that from a url is left with the domain part:

    $url = 'http://misitio.com/uri/uri/loquesea';
    $parse = parse_url($url);
    print $parse['host']; // devuelve misitio.com
    print $parse['scheme'].'//'.$parse['host']; //devuelve http://misitio.com

You can find the parse_url($url) documentation here: link

    
answered by 09.04.2017 в 23:19