Search code examples
phpparse-url

PHP Get Domain With http


I want to get Get Domain from URL and be output: http://www.domain.com/

I found this, but does not come out with the 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'
?>

Output: www.lebanonpost.com

I want it to be: http://www.lebanonpost.com/


Solution

  • Try:

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

    It will work if there is https instead of http

    Test Here