Created
July 31, 2013 07:34
-
-
Save mertenvg/6120059 to your computer and use it in GitHub Desktop.
Trim a domain to a specific number of levels
This file contains hidden or 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
/** | |
* Trim a domain to a specific number of levels | |
* | |
* @param string $domain | |
* @param int $levels | |
* | |
* @return string | |
*/ | |
function trim_domain($domain, $levels = 2) | |
{ | |
if (empty($domain)) { | |
return ''; | |
} | |
return implode('.', array_slice(explode('.', $domain), -($levels))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment