Domanda

Voglio ottenere il dominio Get Domain da URL ed essere output: http://www.domain.com/

L'ho trovato, ma non viene fuori con il http://

<?php
$url = 'http://www.lebanonpost.com/2012/05/20/press-754/';
$parse = parse_url($url);
$domain = str_ireplace('www.', '', parse_url($url, PHP_URL_HOST));
print $parse['host']; // prints 'google.com'
?>
.

Uscita: www.lebanonpost.com

Voglio che sia: http://www.lebanonpost.com/

È stato utile?

Soluzione

Prova:

print $parse['scheme'] . '://' . $parse['host'];
.

funzionerà se c'è https anziché http

Test qui

Altri suggerimenti

È possibile concate http:// alla tua uscita:

<?php
    $url = 'http://www.lebanonpost.com/2012/05/20/press-754/';
    $parse = parse_url($url);
    $domain = str_ireplace('www.', '', parse_url($url, PHP_URL_HOST));
    $domainURL = $parse['scheme'].'://'.$parse['host'].'/';
    print $domainURL;
?>
.

This is the resource I always use for printing url's with PHP - https://stackoverflow.com/a/8891890/1964113

This answer breaks down each piece, even http/https and #fragments.

Google these things man! Really easy to find.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top