getservbyname

Get port number associated with an Internet service and protocol

Syntax

getservbyname ( string $service , string $protocol ) : int

Parameters

service

The Internet service name, as a string.

protocol

protocol is either "tcp" or "udp" (in lowercase).

Return

Returns the port number, or FALSE if service or protocol is not found.

Examples

1 · service protocol

<?

$service = "http";
$protocol = "tcp";

$return = getservbyname($service, $protocol);

echo $return;

?>
80

2 · 1

<?

$array = array("finger", "ftp", "gopher", "http", "imap", "nicname", "pop3", "smtp", "ssh", "telnet", "www");
$protocol = "tcp";

foreach ($array as $service)
{
    $return = getservbyname($service, $protocol);

    echo "$service: $return\n";
}

?>
finger: 79
ftp: 21
gopher: 70
http: 80
imap: 143
nicname: 43
pop3: 110
smtp: 25
ssh: 22
telnet: 23
www: 80
HomeMenu