문제

URL에서 도메인 가져 오기를 얻고 출력 : http://www.domain.com/

나는 이것을 발견했지만, 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'
?>
.

출력 : www.lebanonpost.com

나는 그것을 원한다 : http://www.lebanonpost.com/

도움이 되었습니까?

해결책

시도 :

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

https 대신 http가있는 경우 작동합니다

여기서 테스트

다른 팁

http://에 대해 concate :

<?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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top