function short_hostname($hostname, $len = NULL) { $len = is_numeric($len) ? (int) $len : (int) $GLOBALS['config']['short_hostname']['length']; if (function_exists('custom_shorthost')) { return custom_shorthost($hostname, $len); } elseif (function_exists('custom_short_hostname')) { return custom_short_hostname($hostname, $len); } $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++; } return $short_hostname; }
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; }