HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

getservbyname

Description

The getservbyname of Network for PHP get port number associated with an Internet service and protocol.

Syntax

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

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

<?

$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