Last active
October 24, 2016 14:59
-
-
Save onigetoc/4104739075fb8f9284cc26d97fe1cac4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "<h2>Get Domain and Base URL</h2>"; | |
echo "- Example 1<br>"; | |
$url = "https://francais.rt.com/international"; | |
echo getBaseUrl($url) ; | |
echo "<br>- Example 2<br>"; | |
echo getBaseUrl("https://techcrunch.com/2016/10/23/honeycombtv/?ncid=rss") ; | |
echo "<br>- Get Domain Only<br>"; | |
echo getDomain("https://techcrunch.com/2016/10/23/honeycombtv/?ncid=rss") ; | |
function getBaseUrl($url) | |
{ | |
$parse = parse_url($url); | |
return $parse['scheme'] . '://' . $parse['host']; | |
} | |
function getDomain($url) | |
{ | |
$parse = parse_url($url); | |
return $parse['host']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment