문제
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/
해결책
다른 팁
에 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.
제휴하지 않습니다 StackOverflow