Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DOCME needs phpdoc block
- // TESTME needs unit testing
- function short_hostname($hostname, $len = NULL, $escape = TRUE)
- {
- $len = (is_numeric($len) ? (int)$len : (int)$GLOBALS['config']['short_hostname']['length']);
- if (function_exists('custom_shorthost'))
- {
- $short_hostname = custom_shorthost($hostname, $len);
- }
- else if (function_exists('custom_short_hostname'))
- {
- $short_hostname = custom_short_hostname($hostname, $len);
- } else {
- if (get_ip_version($hostname)) { return $hostname; } // If hostname is IP address, always return full hostname
- $parts = explode('.', $hostname);
- $short_hostname = $parts[0];
- $i = 1;
- while ($i < count($parts) && strlen($short_hostname.'.'.$parts[$i]) < $len)
- {
- $short_hostname = $short_hostname.'.'.$parts[$i];
- $i++;
- }
- }
- if ($escape) { $short_hostname = escape_html($short_hostname); }
- return $short_hostname;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement