質問
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://
を連結することができます:
<?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